-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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(v2): remove trailing slash from router links #2465
Conversation
Deploy preview for docusaurus-2 ready! Built with commit af2eb48 |
Is this truly safe? What if users were doing But I agree we should try to normalize and either add trailing slashes to all or strip all the trailing slashes. |
I do not quite understand what you mean, someone will have links like
`[link](../../)`?
In this PR, an extra (redundant) slash in the current path is removed if
the hosting provider has automatically added it (eg. Netlify). Therefore,
it should not break anything.
пт, 27 мар. 2020 г. в 21:44, Yangshun Tay <[email protected]>:
… Is this truly safe? What if users were doing ../../ to circumvent the
issue and now that we strip the trailing slash, their path will be wrong.
But I agree we should try to normalize and either add trailing slashes to
all or strip all the trailing slashes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2465 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBUIOZMEU2IUV37XVEAODDRJTXZLANCNFSM4LTI6OIA>
.
|
I checked this change with links of more than one nesting level ( |
Oh great, I'll do more testing first. |
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'm not very sure what this PR actually does. If we want to modify the link, why aren't we stripped it from targetLink
and modifying the window.location
instead? Also, causing side effects on the window in the render path of a component doesn't seem like a great idea IMO, not sure if intended.
What side effects do you see here? Removing the trailing slash (which was added by the hosting provider), we process the page as originally "intended" (i.e. without a slash). Therefore, if you call working linking a side effect, then yes, in this case it is. |
The side effect is that you're modifying Why don't we modify the |
Not sure if this will help in the issue solution. Well then I close it, maybe later it will be resolved by someone else. |
Motivation
Resolves #2394
Some hosting providers automatically add a trailing slash to the website links, which leads to the fact that some functionality stops working correctly. For example, in such cases, relative links to other Markdown files do not work. Therefore, to avoid this, we can remove the trailing slash from the internal (which are processed by the router) links before they get to the router. This is safe operation, because we usually get links without a trailing slash, and we can safely delete it.
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
docs/main.md:
docs/sub/index.md:
sidebars.js
Now, when navigating to the
docs/sub/sub
path without a trailing slash and with it (docs/sub/sub/
), the result should be the same:Earlier, when navigating a path with a trailing slash, the result was as follows:
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)