Skip to content

Best way to handle nested routes, where no index page is available for the root endpoint. #11028

Closed Answered by kiliman
thevipinmishra asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thevipinmishra
Comment options

@kiliman
Comment options

kiliman Nov 14, 2023
Collaborator

Answer selected by thevipinmishra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants