Best way to handle nested routes, where no index page is available for the root endpoint. #11028
-
I'm sure the title is confusing, but let me explain it. I want to have my URLs like this, where each flow is "role" based.
Now, this might look straightforward, but the catch here is that, I don't want to render/show anything on Does that make sense? Right now, I'm just doing something like this. if (location.pathname === "/admin" || location.pathname === "/admin/") {
return <Navigate to={path.admin.dashboard} replace />;
} Just manually handling the redirection. Is this the ideal way, or I shouldn't just keep my URLs this way, or is there a better/ideal way to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think redirecting to a default page is fine, but instead of using logic, you can declaratively define this configuration. <Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="admin">
<Route index element={<Navigate to="users" />} />
<Route path="users" element={<AdminUsers />} />
</Route>
</Route>
</Routes> https://stackblitz.com/edit/github-qrmw9l?file=src%2FApp.tsx |
Beta Was this translation helpful? Give feedback.
I think redirecting to a default page is fine, but instead of using logic, you can declaratively define this configuration.
https://stackblitz.com/edit/github-qrmw9l?file=src%2FApp.tsx