-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: keep optional params coming from a parent record #2031
Conversation
✅ Deploy Preview for vue-router ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #2031 +/- ##
==========================================
+ Coverage 90.77% 90.79% +0.02%
==========================================
Files 24 24
Lines 1116 1119 +3
Branches 348 349 +1
==========================================
+ Hits 1013 1016 +3
Misses 63 63
Partials 40 40
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
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.
Thanks!
It should also go for ancestors, not just direct parentsparents have all ancestors- It should have tests about how params with matching names but coming from different routes are discarded
But I'm actually unsure if this is the desired behavior. Currently, matching params are silently passed around and people might find that useful. I wonder if making this behavior stricter will be better in the long term
packages/router/src/matcher/index.ts
Outdated
// only keep optional params coming from a parent record | ||
matcher.keys | ||
.filter(k => !k.optional) | ||
.map(k => k.name) |
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.
This could be done once at the end
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.
- A direct parent's keys contains all optional params, includes ancestors
- I'll open a new PR to improve the code if the behavior it is necessary, absolutely i think this is better to keep the optional params from parent record.
{
path: '/:type?/root',
children: [
{
path: 'path_a',
name: 'a',
},
{
path: 'path_b',
name: 'b',
}
]
}
// current path: '/optionType/root/path_a'
resolve({
name: 'b'
});
I think /optionType/root/path_b
is better than /root/path_b
in this case
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 guess o forgot how I wrote my own code 😂
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 suggest to keep optional params coming from a parent record, that is really useful
@posva hey, i have improved the code and add unit tests |
thanks! I will check later on this year |
resolve TODO: only keep optional params coming from a parent record