-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Private routing[Feature]: #8495
Comments
There are solutions: function App() {
return (
<Routes>
<Route path="admin/*" element={<AdminPage />} />
</Routes>
);
}
function AdminPage() {
const isAdmin = useIsAdmin();
if ( isAdmin ) {
return (
<Routes>
<Route path="users" element={<UsersPage />} />
{ /* some other routes */ }
</Routes>
);
}
return (
<div>You're not allowed to access this page!</div>
);
} |
This is already one of the examples: https://reactrouter.com/docs/en/v6/examples/auth |
Apologies for commenting on a closed issue, but can I ask - the comment here - https://stackoverflow.com/a/69592617/1849358 seems to offer a much 'nicer' approach to private routes, with no replication of having to wrap each private element. Does this seem like a valid solution? Particularly since in https://reactrouter.com/docs/en/v6/getting-started/concepts#layout-routes you recommend not to wrap the elements with |
Co-authored-by: Matt Brophy <matt@brophy.org>
What is the new or updated feature that you are suggesting?
Private routing to prevent unauthorised users to certain routes. All the implementations ive seen so far doesnt use your latest version. Please if you have any idea to implement it, I'd love to learn it. Thanks
Why should this feature be included?
to prevent unauthorised users to certain routes.
The text was updated successfully, but these errors were encountered: