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

Fixed NavLink Issue #10734

Merged
merged 12 commits into from Oct 31, 2023
Merged

Fixed NavLink Issue #10734

merged 12 commits into from Oct 31, 2023

Conversation

bilalk711
Copy link
Contributor

@bilalk711 bilalk711 commented Jul 24, 2023

Original Issue

NavLink active breaks when to contains trailing slash

Steps to Reproduce

Create a NavLink with end omitted or set to false and with to set to a route path which contains sub-routes and ensure a trailing slash at the end.
Visit a sub-route of the path in use.

Expected Behaviour

With end false, when the current location is a sub-route of a mounted NavLink, then it should be active.

Actual Behaviour

NavLink is considered inactive.

This issue is fixed in this PR.

@changeset-bot
Copy link

changeset-bot bot commented Jul 24, 2023

🦋 Changeset detected

Latest commit: 288a6d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
react-router-dom Patch
react-router Patch
react-router-dom-v5-compat Patch
react-router-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jul 24, 2023

Hi @bilu7111,

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 Jul 24, 2023

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

@timdorr
Copy link
Member

timdorr commented Jul 26, 2023

Just as an FYI, your commits aren't attributed to your GitHub account because you don't have your Git email address added. If you add bilal@dubicars.com to GitHub, you'll get attribution to those commits and the CLA bot will be happy :)

@bilalk711 bilalk711 closed this Jul 28, 2023
@bilalk711 bilalk711 reopened this Jul 28, 2023
@bilalk711
Copy link
Contributor Author

Just as an FYI, your commits aren't attributed to your GitHub account because you don't have your Git email address added. If you add bilal@dubicars.com to GitHub, you'll get attribution to those commits and the CLA bot will be happy :)

Actually the issue was that I changed my username but forgot to add that to contributors.yml

Copy link

@iamdey iamdey left a comment

Choose a reason for hiding this comment

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

It's a bit out-of-scope but it would be nice to change the documentation to make it consistent with reality:

https://reactrouter.com/en/main/components/nav-link#end

Without the end prop, this link is always active because every URL matches /.

- <NavLink to="/">Home</NavLink>
+ <NavLink to="/page">Page</NavLink> 

+ Exception for `/` which will be active only when url match path exactly

To match the URL "to the end" of to, use end:

- <NavLink to="/" end>
+ <NavLink to="/page" end>
  Home
</NavLink>





Link | URL | isActive
-- | -- | --
<NavLink to="/tasks" /> | /tasks | true
<NavLink to="/tasks" /> | /tasks/123 | true
+ <NavLink to="/tasks/" /> | /tasks | true
+ <NavLink to="/tasks/" /> | /tasks/ | true
+ <NavLink to="/tasks/" /> | /tasks/123 | true
<NavLink to="/tasks" end /> | /tasks | true
<NavLink to="/tasks" end /> | /tasks/123 | false
+ <NavLink to="/tasks/" end /> | /tasks | false
+ <NavLink to="/tasks/" end /> | /tasks/ | true
+ <NavLink to="/tasks/" end /> | /tasks/123 | false

@bilalk711 bilalk711 requested a review from iamdey July 31, 2023 12:59
@bilalk711
Copy link
Contributor Author

@iamdey can you merge it now if you have write access?

@bilalk711
Copy link
Contributor Author

Updated the documentation as per new changes.

@bilalk711
Copy link
Contributor Author

@brophdawg11 Do you have write access or can you mention someone with authority who can merge this PR?

@timdorr timdorr requested review from brophdawg11 and removed request for iamdey September 27, 2023 16:29
@brophdawg11 brophdawg11 merged commit e6ac5f0 into remix-run:dev Oct 31, 2023
3 checks passed
Copy link
Contributor

🤖 Hello there,

We just published version 6.19.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 6.19.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

jonathanpruvost pushed a commit to concordnow/react-router that referenced this pull request Nov 28, 2023
Co-authored-by: Bilal Kazmi <bilal@dubicars.com>
Co-authored-by: Bilal Kazmi <bilu71115@gmail.com>
Co-authored-by: Matt Brophy <matt@brophy.org>
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.

None yet

4 participants