Migration nested routes from v5 to v6 #8385
-
I am trying to migrate routes from v5 to v6 and am having difficulties with nested routes using params.
PeopleComponent
When I try to access the edit or destroy route, params.personId always is undefined. |
Beta Was this translation helpful? Give feedback.
Answered by
MeiKatz
Nov 24, 2021
Replies: 1 comment
-
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> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
costafacchini
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: