-
-
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
feat: throw if parent and child routes have the same name #2267
Conversation
✅ Deploy Preview for vue-router canceled.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2267 +/- ##
==========================================
+ Coverage 90.96% 91.01% +0.04%
==========================================
Files 24 24
Lines 1151 1157 +6
Branches 355 358 +3
==========================================
+ Hits 1047 1053 +6
Misses 64 64
Partials 40 40 ☔ View full report in Codecov by Sentry. |
How can i make / to Home , make /foo to Foo , while all the left "/:pathMatch(.*)" to PAGE_NOT_FOUND ? |
@sherleysong I don't fully understand your question, but you need to remove the |
It worked , thank you ! The running code was { path: '/', name: 'home', component: Main, redirect: '/home', children: [ { path: '/home', name: 'home', component: Home }, { path: '/:pathMatch(.*)', component: () => Error } ] } @vue-router@4.3.2, when we visit www.xxx.cn , it will redirect to Home. as you recommended , i removed the Anyway , it worked for me , thank you again! |
Thanks for this. I really didn't expect people to fall into this but I was wrong |
#2266 demonstrated an edge case that can lead to inconsistent internal state in the matcher.
The problem arises when using nested routes. If the child (or deeper descendant) has the same
name
as its parent, the parent is removed at the same time that the child is added.Removing a parent route should also remove its children, but in this case that removal happens just before the child is added to the matcher. The child still gets added to the matcher, and its
parent
property still points to the parent route, even though that has now been removed. The parent can no longer be resolved directly, but when resolving the child, thematched
array will still contain the removed parent.This problem can occur during the initial router creation:
It can also happen when adding a route dynamically:
This PR introduces a dev-only check for ancestors with the same name and throws an error if a duplicate is found.