Skip to content

Migration nested routes from v5 to v6 #8385

Closed Answered by MeiKatz
costafacchini asked this question in Q&A
Discussion options

You must be logged in to vote

useParams() is relative to the most inner route context it was called. In your case it is above the definition of :personId and therefore it is not defined. You could something like this:

function PersonComponent() {
  const params = useParams();

  return (
    <Routes>
      <Route path="" element={<ShowComponent />} />
      <Route path="edit" element={<EditComponent resource={params.personId} />} />
      <Route path="destroy" element={<DestroyComponent resource={params.personId} />} />
    </Routes>
  );
}

<Routes>
  <Route path="/" element={<IndexComponent />} />
  <Route path=":personId" element={<PersonComponent />} />
</Routes>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by costafacchini
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