I am trying to create an new react app. I have 3 components: app (with login functionality) , admin and client.
- How can I render (redirect to) admin / client based on a value (user role) , after successfully login?
- Is this any way to access the admin / client components directly from the URL? More specific, localhost:3000 takes me to App.js (witch makes sense, because it is defined like this in index.js). If I want to see directly the admin component (hijacking the login), can I use for example localhost:3000/admin ? how can I do that?
Thank you !
CodePudding user response:
You can use react-router, that allow to define some route based on URL. When you have a login feature, then you would probably wants to have some protected route, that are only accessible when you are logged in. Then I recommend you to read this article
CodePudding user response:
You can use react router and in particular
route.push('/admin')
You need to define the '/admin' route and voilà.
To bypass the login, you may want to make a 'test-admin' route and a private 'admin' route. Here is how to make a private route if you happen to need it:
https://dev.to/karanpratapsingh/private-public-and-restricted-routes-in-react-42ff