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

[Bug]: Relative path's on splat routes are broken #11038

Closed
gijsroge opened this issue Nov 17, 2023 · 7 comments
Closed

[Bug]: Relative path's on splat routes are broken #11038

gijsroge opened this issue Nov 17, 2023 · 7 comments
Labels

Comments

@gijsroge
Copy link

gijsroge commented Nov 17, 2023

What version of React Router are you using?

6.19.0

Steps to Reproduce

Create a route with a relative="path" option in a splat route that either goes forward, or backward. Non splat routes are working fine.

Expected Behavior

The navigation should respect the relative path

Actual Behavior

It goes back to the root.

Let's say you are on page /a/b/c and you link to d using relative="path" it goes to /d instead of /a/b/c/d

Reproduction in Remix: https://stackblitz.com/edit/remix-run-remix-jb8sq2?file=app%2Froutes%2F%24.tsx

I'm guessing it has something to do with the latest change, because if I revert back to an earlier version of Remix there is no issue.

@gijsroge gijsroge added the bug label Nov 17, 2023
@kiliman
Copy link
Contributor

kiliman commented Nov 17, 2023

Yes, I think it's wrong as well. When you select relative="path", it should do path resolution against the current URL, not the current route (since the default for navigation is relative to route definition).

For splat routes at the root, the route path would be /, not /a/b/c as the current URL.

Also, I would say that /a/b/c => d would be /a/b/d. Because technically you would treat c as a file, not a folder.

If you want /a/b/c/d then the current URL should be /a/b/c/ (trailing slash).

let u = new URL('d', 'http://localhost/a/b/c')
// u.pathname = '/a/b/d'
let u = new URL('d', 'http://localhost/a/b/c/')
// u.pathname = '/a/b/c/d'

@gijsroge
Copy link
Author

gijsroge commented Nov 18, 2023

@kiliman thanks for confirming!

About the trailing slash. Not sure if that's ideal because most websites do not use a trailing slash and this would change the behavior of the relative="path" feature and introduce a breaking change.

@MaximeBernard
Copy link

I can confirm as well. All our apps are "broken" (active tab is not displaying active anymore).

This is a breaking change and should then be flagged as a major update.

@brophdawg11
Copy link
Contributor

This looks like a bug related to both #10983 and #11006 - we'll get a fix in for this 👍. I think we just need the change from #10983 in a second code path.

if I revert back to an earlier version of Remix there is no issue.

Interestingly enough, this was an issue in prior versions without relative="path" (i.e., <Link to="test">), but the above PRs caused the issue to show up in 2.3.0 with and without relative="path"

should do path resolution against the current URL

This is not quite accurate. relative=path is only intended to impact the resolution of ".." - does that mean "go up one route in the hierarchy" or "go up one URL segment". Routes are still relative to the current location in context - which is the bug being fixed by #11006.

@brophdawg11
Copy link
Contributor

This is fixed in #11045 and will be available in the next release

@brophdawg11 brophdawg11 added the awaiting release This issue have been fixed and will be released soon label Nov 20, 2023
@brophdawg11 brophdawg11 removed their assignment Nov 20, 2023
Copy link
Contributor

🤖 Hello there,

We just published version 6.20.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 6.20.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants