-
Notifications
You must be signed in to change notification settings - Fork 760
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
Fix non-routing Link component usages (#210) #231
Fix non-routing Link component usages (#210) #231
Conversation
The maintainers of this repository would appreciate it if you could provide more information. |
|
||
function isRoutingUrl (to) { | ||
if (typeof to !== 'string') return true | ||
return !to.match(/^#/) && !to.match(/^[a-z]{1,10}:\/\//) |
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.
Will this work when using the hash
version of the Router?
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.
Good point, I haven’t tried it.
It should work, as the user of the components should still provide a proper, non-fragment URL, it is the responsibility of history
/react-router
to encode the output in whatever format they currently need.
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.
I can try and verify it, maybe tomorrow.
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.
No meaningful BC breakages, here are the findings:
-
<Router type="hash">
and regular links keep working.<Link to="about">
matches ourisRoutingUrl
check and thus gets passed through to react-router, which renders a<a href="#/about">
. -
<Router type="hash">
and links that manually have the hash route kind of work.<Link to="#/about">
does not match ourisRoutingUrl
check and gets rendered with the newly introduced shortcut into a<a href="#/about">
. react-router handles this links, so it responds to user interaction and changes routes, but it does not havearia-current
. We could attempt to distinguishto="#/about"
as a non-fragment link, but technically ids can start with a slash. The usage<Link to="#/about">
is already kind of wrong, and with proper history support nearly universal, I don’t think we have to worry about this. -
<Router type="hash">
and fragment links are still broken after the latest changes.<Link to="#subheading">
gets rendered with the newly introduced shortcut into a<a href="#subheading">
, but is still handled by react-router to navigate to#/subheading
, ignoring the fragment link. This was already broken with the react-router<Link>
, and is still broken with our manually rendered<a>
. Nothing to see here.
The documentation for It might also cause some confusion that a hash |
If a package user decides that for hash links they need a manual
Hypothetically, yes. But those are extra features that someone with an understanding of routing should expect, but then they should also expect them to not work. Still, you’re right, so I’ve added a warning in #232. |
#210