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

Respect trailing slash when basename is used #8861

Merged
merged 5 commits into from
Jun 21, 2022

Conversation

senseibarni
Copy link
Contributor

@senseibarni senseibarni commented May 12, 2022

I am aware that the tests are not the best as they do not test actual code. The thing is that for this case the fully functional test is really hard to achieve. I tried with MemoryRouter and BrowserRouter. The real problem is only visible in the browser URL bar. window.location is not working well (because of the basename). Maybe someone smarter will come up with something or the test can be skipped as the changes don't look ambiguous.

fix #8312
fix #6226

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented May 12, 2022

Hi @senseibarni,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented May 12, 2022

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@remix-run remix-run deleted a comment from changeset-bot bot May 12, 2022
@ryanflorence
Copy link
Member

React Router shouldn't care about trailing slashes, if it's there, leave it, if it's not, don't add it.

@brophdawg11 you want to add to this PR to work that out and get some tests on it?

@ryanflorence ryanflorence changed the title #8312 and also #6226 Respect trailing slash when basename is used Jun 10, 2022
@brophdawg11
Copy link
Contributor

👋 Thanks for the PR @senseibarni! I made some updates and corralled all the tests into a central location. I think this now properly handles being trailing-slash-agnostic for both Navigate (via useNavigate) and Link (via useHref). I still want to give a bit of a closer look at the linked issues still, but ran out of time today and will get back to that this weekend or Monday 👍

element={
<>
<Link to="" />
<Link to="/" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aiming to leave trailing slash behavior in the hands of the user here and effectively treat paths as basename + link. If they do not include a trailing slash on their basename, then they can control the trailing slash behavior via <Link> such that <Link to="/"> will include the trailing slash and <Link to=""> will not.

If they do include a trailing slash on the basename, then it will be included on all links.

Comment on lines +297 to +302
<a
href="/app/"
/>,
<a
href="/app/"
/>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the basename has a trailing slash, routes to the root route will always have the trailing slash, but users still control trailing slash behavior on nested locations (see /app/parent/child below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. getWindowImpl was missing part when I was trying to write some decent tests. Good to know how to manage such cases 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants