Nested Path Params in React Router not working properly
I want to display all the comments of a given post and when I click in a comment it takes me to a page with $commentId: /posts/$postId/comments/$commentId
Right now I can only display the posts but I can't show their corresponding comments, let alone go to the commentId path
I have this file structure for now:
posts.route.tsx
posts.index.tsx
post.$postId.tsx
post.$postId.comments.tsx
never executes but the path changes in the address bar
2 Replies
optimistic-gold•2w ago
that's because $postId is a parent of $postId.comments, so it renders
your $postId should instead be $postId.index.tsx
same with $postId.comments vs $postId.comments.$commentId,
$postId.comments -> $postId.comments.index
the .index makes it so that a route cannot be a parent of any other route
and thus never match routes with similar subsections
wee-brownOP•2w ago
it worked perfectly