-
Notifications
You must be signed in to change notification settings - Fork 968
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 not highlighting when on sub pages #6939
Conversation
Hey @razzeee, thanks for writing a test, it makes what you're looking for super clear. Yeah it doesn't work like this— |
I've pushed an iteration, not too proud of it and probably multilpe things to improve. Not sure about that whole params part for e.g. And also not sure if the logic should also allow matching for inbetween paths like |
packages/router/src/util.ts
Outdated
paramTypes?: Record<string, ParamType>, | ||
matchChildRoutes = false |
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.
Now that we have so many arguments to this function, could you please switch to an options object instead? Either for all of them, or for just the last two.
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.
Wouldn't that change the api? Is it safe to assume, that this is only used internally?
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.
That's a good shout! The "public version" is supposed to be the useMatch
hook. But we are also exposing this function, so while it's ment to be internal only, it really isn't.
Let's leave it as it is for now and I'll ask the rest of the team. We are about to release RW v4 fairly soon. So if we are to introduce a breaking change that would be a good time to do it :)
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 switched to an options object, but I also kept the old way of calling the function, but with a deprecation notice.
The change that this PR introduces is something I need in one of my own projects now, so keen to get it merged. And always easier to merge without breaking changes :D
It's a great first iteration. Thanks for putting in the time and effort! I did have a few comments, but hopefully nothing too difficult to address. Also don't hesitate to tell me I'm wrong about any of the comments 🙂
I say we skip this for now, and then come back and add support for that when/if someone explicitly asks for it and shows a good usecase |
I pushed two more tests. They are currently failing. I think they should pass, but please tell me if you don't agree. I've also asked about the breaking change to |
Fixed the failing tests and added another one, that's relevant. The params part still feels fishy to me. |
Hey @razzeee @Tobbe some interest in this came from discord today
Any thoughts on time to merge? |
I need to review; so just waiting on me. I’ll get to it soon! |
My thoughts are...
If we agree I'm happy to make these changes. |
Agreed, I think I renamed stuff to |
This reverts commit 1b2016b.
Thanks a lot for your review Dom. It sparked some other ideas for me. Please let me know what you think.
Good point about
To keep backwards compatibility I introduced a new method for the new functionality. So no need for an options object. But I can introduce one for the new method I created (with just one option for now) if we want to make it more future proof. Keeping it the way it is makes both exported functions have the same signature, which I like. |
I'd prefer const internalMatchPath = (
route: string,
pathname: string,
{
paramTypes,
matchChildRoutes,
}: {
paramTypes?: Record<string, ParamType>
matchChildRoutes?: boolean
}
) => {
...
} That's two options isn't it? Maybe this isn't the new one you created though since it's prefaced with |
I should have been more clear. I meant the new exported function. It takes the same parameters as the original function. Should I rename @razzeee I value your input on naming too 🙂 |
At first this was my reaction too. But thinking about it more I actually don't mind enabling advanced usage of Redwood with these functions. |
We talked about this PR on a team meeting today.
Still not 100% clear on if we can release this in a minor, or if it'll have to wait until v4 (RC out next week, GA in January) I'll start working on those points asap |
…xperimental-vite-optin * 'main' of github.com:redwoodjs/redwood: (27 commits) fix(deps): update dependency @types/node to v16.18.9 (#7140) fix(deps): update dependency vscode-languageserver-textdocument to v1.0.8 (#7132) fix: add cli-helpers as dep (#7141) remove deprecated auth providers (#7138) chore: update test project fixture dbauth packages (#7139) NavLink not highlighting when on sub pages (#6939) Rename create auth functions (#7137) Export underlying cache client with Service Cache functions (#7062) fix(deps): update dependency @simplewebauthn/browser to v6.2.2 (#7103) fix(deps): update dependency msw to v0.49.2 (#7126) chore(deps): update dependency nx to v15.3.3 (#7125) fix(deps): update docusaurus monorepo to v2.2.0 (#7116) [docs] How to test in GitHub actions (#6921) fix(deps): update typescript-eslint monorepo to v5.46.1 (#7109) Codemod to include full-name in test-project signup (#7124) Rebuild test-project fixture (#7123) feat: add CustomValidator (#7051) dbAuthClient (#7111) chore(deps): update dependency nx to v15.3.2 (#7114) chore(deps): update dependency redis to v4.5.1 (#7115) ...
Hey there,
this is more of a question, as I'm pretty surprised this doesn't work (like this).
I thought writing a test would be the sane thing to check if I'm really not doing anything wrong and at the same time to explain, what I'm trying to do.
Cheers
Release Notes
The
<NavLink>
component takes a new prop,matchSubPaths
that will make it apply theactiveClassName
className also for sub path matches. So if you have a NavLink to /posts it will also add the active class name when the user is on, for example, /posts/2 or /posts/newThe
useMatch
hook takes the same parameter and will then also match sub paths.matchPath
is no longer exported from@redwoodjs/router
. If you're using it we recommend you use theuseMatch
hook instead. IfuseMatch
doesn't cover what you were usingmatchPath
for, please let us know.