-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
NavLink isActive is not returning true on all paths with multiple paths on same component #6759
Comments
NavLink doesn't expect the path to be an array. We should probably handle that. |
IIRC the path array is local to the But we probably should allow NavLink to also "match" multiple paths just like Route. #5368 would offer a way to hack that in manually. Not sure how we could do this cleanly. Allowing an array for the "to" prop is a bit icky: <NavLink to={["/", "/two"]} /> And stuffing the path array into the match object is a bit hacky too. |
That wouldn't work semantically anyways. Which path does that link to exactly? |
I had another idea: We do have an isActive function https://reacttraining.com/react-router/web/api/NavLink/isactive-func We could provide a helper function for matching a path array: <NavLink to="/" isActive={onPaths(["/", "/two"])} /> Edit: here is a sandbox demonstrating it: https://codesandbox.io/s/react-router-63bti Another way would simply to add another prop: <NavLink to="/" alternatePaths={["/", "/two"]} /> |
Eh, that seems like low value for what is just this: <NavLink to="/" isActive={({ path }) -> ["/", "/two"].includes(path)} /> |
you mean <NavLink to="/" isActive={(_, { pathname }) => ["/", "/two"].includes(pathname)} /> |
so I am trying to do this or something similar, and I am running into the same issues. I want to link to a particular place, but light up the link if it is kind of nearby. what I want to be able to do is something like... <NavLink to="/one" path={["/one", "/two"]}/> more concrete example: I want to click on the link to go directly to a recent user, but the link should show that the section is active regardless of which user or any is selected. <NavLink to="/users/abc123" path={["/users"]}/> I tried using the is there some trickery that can be done with the current API to get this to work? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Version
5.0.0
Test Case
https://codesandbox.io/s/react-router-1pf7h
Steps to reproduce
<Route>
with multiple pathsactive
prop likeactiveClassName
oractiveStyle
on<NavLink>
Expected Behavior
Maybe I'm totally off here and misunderstood something fundamental, but in my mind it would make sense that both
/
and/two
in the test case should be active when url is/
Actual Behavior
Only
/
is active when url is/
when both/
and/two
are set ass paths for theHome
component.The text was updated successfully, but these errors were encountered: