vue-router icon indicating copy to clipboard operation
vue-router copied to clipboard

addRoute() with name couldn't replace the existing rule with the same name.

Open klwfwdk opened this issue 4 years ago • 10 comments

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'

klwfwdk avatar Apr 09 '21 08:04 klwfwdk

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

posva avatar Apr 09 '21 09:04 posva

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

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.

klwfwdk avatar Apr 09 '21 11:04 klwfwdk

Hello. Agree with @klwfwdk . The docs are stating this should be possible in 3.5.0 but it is not.

dinokopriva avatar Jun 01 '21 14:06 dinokopriva

Please update the documentation, this is frustrating.

mitchierichie avatar Jan 25 '22 19:01 mitchierichie

Sorry to bother here ; is there a known workaround ?

bourdaisj avatar Feb 25 '22 16:02 bourdaisj

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!

timhere avatar Jan 20 '23 11:01 timhere

Is there a known workaround for this issue?

ChristopherJohnson25 avatar Jul 13 '23 15:07 ChristopherJohnson25

I believe the only workaround would be to fork vue-router and modify the behaviour as in #3519

timhere avatar Jul 13 '23 17:07 timhere

Reporting we have the same issue and was confused as the docs said this should overwrite an existing route. A couple hours wasted.

digitalkog avatar Dec 05 '23 17:12 digitalkog

+1 here as well for docs change, though porting over removeRoute to 3.5 would also be welcome.

blackdwarf avatar Dec 05 '23 22:12 blackdwarf