-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
use useHref'ed href for router based navigation #7695
base: main
Are you sure you want to change the base?
Conversation
) { | ||
e.preventDefault(); | ||
router.open(e.currentTarget, e, props.href, props.routerOptions); | ||
router.open(e.currentTarget, e, routerLinkProps.href, props.routerOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routerLinkProps.href is the useHref value, so that relative links are computed correctly. For instance if you are under /blogs in React Router, useHref will compute "/blogs/1" if href="1"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative might be to call it with e.currentTarget.href
The test failures make sense broadly in that its not expecting to use the full path from useHref for navigation.
would be the fix |
@devongovett i think you wrote the related code originally? |
Thanks for the PR, you'll need to sign the CLA https://react-spectrum.adobe.com/contribute.html#contributor-license-agreement Thanks again! |
That's not a problem, the key question is if the updated behaviour is correct or is the current behaviour "as designed" or something. Also how to potentially handle host based links like https://example.com which are quasi-broken even now afaict. |
This reverts commit 0288f4c950879a7aa13008d62dc1491f30085739.
1853f2e
to
50c495a
Compare
Another alternative would be to add an isExternal flag on the Link component |
This is a breaking change. Shouldn't the router be handling this in the |
Great question:
works fine, I'm not sure why it fails with react-aria. |
I think it might depend on where the You could fix this by calling |
Closes #5476 (comment)
This make require a lot of setup for testing, but generally speaking relative links in routers don't work because the useHref'ed value is not used for navigation.
Originally investigated in heroui-inc/heroui
✅ Pull Request Checklist:
📝 Test Instructions:
https://stackblitz.com/edit/wfdcu9f2-5zvxtaag?file=App.jsx has a comparison of the React Router link and RA link behavior for the relative link. Go to
/blogs
in the previewIt is also worth noting that the http:// link href is wrong as well, perhaps the href return value in linkProps should also be guarded with shouldClientNavigate somehow
🧢 Your Project:
https://www.rhino-project.org/ , https://www.heroui.com/ (I'm not affiliated with them, but they are a user of this lib where this first showed up)