vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.77k stars 1.16k forks source link

Router omits current route when navigating by name in shared subroute context #2116

Closed lucastanger closed 6 months ago

lucastanger commented 6 months ago

Reproduction

https://codesandbox.io/p/sandbox/icy-river-y3ppgk?file=%2Fsrc%2Fmain.js%3A14%2C6

Steps to reproduce the bug

  1. Open Codesandbox
  2. Ensure router is visiting "/random/static1"
  3. Click Button "Go to subroute"
  4. See router switching to "/random/static2/subroute/1"

Expected behavior

Router stays on route static1 and appends subroute

Actual behavior

Router is switching from static1 to static2 and then appends subroute

Additional information

While creating this issue, I realized that this could be caused due to the fact that the subroute is a "shared" property used by both route static1 and static2. I would expect that I can create new routes and append them to different routes as children, but keep the current active route as active.

router --/:prop/static1 ------------/:prop/static1/subroute/:id (aliased as 'subroute') <--- Switches from this to static2, while only submitting the name 'subroute' --/:prop/static2 ------------/:prop/static2/subroute/:id (aliased as 'subroute')

posva commented 6 months ago

names are uniques so you need to ensure that your two subroutes use different names instead of just subroute for both of them