How to properly redirect between different views in Laravel & Inertia with multiple React instances? #2157
Unanswered
mostafa-A48
asked this question in
Help (React)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working on a Laravel web application with two distinct user interfaces: one for admin users and another for portal users. To manage these interfaces, I have created two separate React instances with different JavaScript paths:
resources/js/app.jsx for the admin panel resources/portal-js/app.jsx for the portal The logic for determining the root view is defined in my HandleInertiaRequests.php file:
Problem: When a user logs in, the application is supposed to redirect them to the appropriate interface (admin or portal) based on their user role. However, I encounter the following issues:
Login redirection:
If the user is a portal user, the app fails to load the correct React instance and cannot find the required components for the portal interface. The same happens when logging out from one interface and trying to switch to the other.
Component resolution: Each React instance uses its own resolvePageComponent() function with laravel-vite-plugin. Here’s the setup for each:
Admin React instance
(resources/js/app.jsx)
:Portal React instance
(resources/portal-js/app.jsx)
:Observations:
The login route always uses the admin React instance, even when the user should be redirected to the portal interface. The components for the other interface are not found when switching between admin and portal.
Question:
How can I ensure that the correct React instance is loaded based on the user type? Is there a recommended way to handle separate React instances for different user interfaces in a Laravel-Inertia application? Should I structure my application differently to avoid this issue altogether? Any guidance or examples would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions