vuejs / router

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

Router link not set as active when navigating programmatically with optional prop #2019

Closed jcmillett closed 10 months ago

jcmillett commented 10 months ago

Reproduction

https://jsfiddle.net/roc93bnt/

Steps to reproduce the bug

  1. In the JSFiddle provided, try clicking on the Foo link and notice (true) appears indicating that the link is active.
  2. Now try clicking on the Navigate to Foo with ID 2 button and notice that the foo link displays (false) indicating that the link is not active.

I would expect the foo link to be active when navigating to the foo path with the ID prop as a path variable.

Expected behavior

router-link's should be active and have active class applied when navigating programmatically using props.

Actual behavior

router-link's are not being set as active and do not have active class applied when navigating programmatically using props.

Additional information

No response

posva commented 10 months ago

This is working as expected. See https://router.vuejs.org/guide/migration/#Removal-of-the-exact-prop-in-router-link- and the mentioned RFC for more details. In your case, it's all about what router.resolve('/foo') resolves to and you will likely have to write your custom logic for is active if you want { name: 'foo' } to be active when the route is { name: 'foo', params: { id: ... }}.