addRoute() with name couldn't replace the existing rule with the same name.
Version
3.5.1
Reproduction link
https://github.com/klwfwdk/addroute-issue
Steps to reproduce
1.click to call router.addRoute() to add a new router named 'About' witch has the same name attribute with a route rule already existing. 2.click router-link 'About'
What is expected?
the route overwrite into new one. The browser should show 'This is an about page New'
What is actually happening?
Still appears as an unupdated component. The browser showed 'This is an about page'
This is a misalignment with v4. We should be able to fix the simple cases without aliases by removing routes from namedMap, pathMap and pathList but It might have some edge cases that aren't fixable without a removeRoute() (v4 only) API. I think it's worth at the very least remove root routes and probably children routes but this requires a bit more investigation to see the side effects.
Note dynamic routing is not supported in vue router 3
This is a misalignment with v4. We should be able to fix the simple cases without aliases by removing routes from
namedMap,pathMapandpathListbut It might have some edge cases that aren't fixable without aremoveRoute()(v4 only) API. I think it's worth at the very least remove root routes and probably children routes but this requires a bit more investigation to see the side effects.Note dynamic routing is not supported in vue router 3
In this case, I feel the description should be removed from the document, or a warning should be made. The current description is misleading。
In https://router.vuejs.org/api/#router-addroutes,
Add a new route to the router. If the route has a name and there is already an existing one with the same one, it overwrites it.
Hello. Agree with @klwfwdk . The docs are stating this should be possible in 3.5.0 but it is not.
Please update the documentation, this is frustrating.
Sorry to bother here ; is there a known workaround ?
This has been an issue for over a year and a half, yet it is still detailed in the documentation as a working method for >3.5.0.
I believe the open PR #3519 fixes this issue. If this is not planned to be fixed can we remove it from the docs ASAP? I'm sure there are many like me who are losing days to trying to get this working before unearthing this issue via a search!
Is there a known workaround for this issue?
I believe the only workaround would be to fork vue-router and modify the behaviour as in #3519
Reporting we have the same issue and was confused as the docs said this should overwrite an existing route. A couple hours wasted.
+1 here as well for docs change, though porting over removeRoute to 3.5 would also be welcome.