-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for router base path #5395
Conversation
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.
LGTM
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.
Thanks for your contribution! There is one change relating to how we RSP does imports.
Is this something that React Aria needs to be aware of? Perhaps it would be better to use React Router's API to solve this problem instead? Their useHref hook should handle this. import {useHref} from 'react-router-dom';
<MenuItem href={useHref('...')} /> I would prefer this approach because it keeps React Aria closer to native HTML behavior, and agnostic to any particular router. |
Basename behavior is not unique to react-router. Next.js also supports setting a basename as does TanStack router. The naming of it might be updated to be basePath perhaps which might make more sense. The With react-aria taking over the responsibility of creating the anchor tag, this creates a problem since react-aria doesn't know about the basename, so it's using the same href for both calling Technically your suggestion does work if you also wrap the The same actually goes for the I also think the behavior would be very confusing as it would vary between react-aria managed links and those that aren't. If you use the import { Link } from 'react-router-dom'
import { MyLibraryLink } from '@/components/MyLibraryLink'
<Link to="/admin" />
<MyLibraryLink href={useHref("/admin")} /> Sorry, this comment got pretty long, late night brain dumping my thoughts on this 🤣 |
It looks like the PR has a failing test. Are you able to fix that? |
@ktabors Thanks, I updated to |
I wonder if you've tried to use the HTML Let me know if you try that out. If it works, I'd prefer to add that to the docs rather than adding additional functionality to append/strip the url ourselves. |
@devongovett I did some experimenting with In-page anchors (e.g. React Router (and I presume other routes as well) will transform links from relative to absolute paths. As such, nothing passed to the However, the same would not be true of react-aria. If you have |
@mskelton Did you make it work with NextJS or with React Router? I've been facing the same issue on NextJS and I couldn't figure out a workaround while I wait for this to merge (and I don't know how much it'll take @reidbarber to review it). I've seen a related one but for RR, so if in your case it's for NextJS and you could provide it, it'll be awesome. Thank you! |
@GustavoSmith The workaround I used was to manually add logic that would apply the base path to all links I pass to react-aria components before rendering them and then use a function to wrap the |
Thanks for providing details on your workaround. We're considering a solution like what is described in this comment on another issue #5476 (comment). We believe it would address your issue as well. |
Closes #5335
✅ Pull Request Checklist:
📝 Test Instructions:
basePath
prop to theRouterProvider
href
should include the base path, but the base path should be removed when calling thenavigate
function.🧢 Your Project: