Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to grandchild route broken in 2.3.0 #8068

Closed
WillSmithTE opened this issue Nov 20, 2023 · 2 comments
Closed

Link to grandchild route broken in 2.3.0 #8068

WillSmithTE opened this issue Nov 20, 2023 · 2 comments

Comments

@WillSmithTE
Copy link

Reproduction

https://stackblitz.com/edit/remix-run-remix-gbbwif?file=app%2Froutes%2F_.%24userId.blog.tsx

  • Have a grandparent route (_), parent (_.$userId) and child (_.$userId.blog).
  • From grandparent, use a Link <Link to="blog" relative="path">

System Info

It's same in stackblitz

Used Package Manager

npm

Expected Behavior

Clicking "Blog" shows the Blog route (Blog stuff goes here).

Actual Behavior

On 2.3.0, the route changes to /blog.

On 2.2.0, (the version in the blitz), the route correctly navigates to /$userId/blog

@brophdawg11
Copy link
Contributor

This is due to a bug fix in React Router 6.19.0 where when relative="path" was specified, we were losing the contextual route starting point. This meant that the link href changed values every time you navigated since it was not properly tied to the contextual route.

All routing in React Router should be relative to the current route hierarchy, so relative links (or links starting with ./) start at the current location in the tree. Specifying path=relative changes the behavior of how .. works - by default it traverses the route hierarchy, but you can tell it to instead traverse the path by URL segment.

In your example, the Link in _.tsx is relative to that route (path /), so <Link to="blog" relative="path> now correctly results in /blog. If you want it to tack onto the end of the current pathname you have a few options:

// Use the current location
let location = useLocation();
<Link to={`${location.pathname}/blog`}>

// Or construct via the current params
let params = useParams();
<Link to={`${params.userId}/blog`}>

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2023
@WillSmithTE
Copy link
Author

I guess your bug was my feature!

But thanks for the quick resolution, appreciate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants