vuejs / router

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

problem in watch query of route #2143

Closed mohamadkhalili closed 7 months ago

mohamadkhalili commented 7 months ago

Reproduction

https://codesandbox.io/p/sandbox/lively-breeze-xy5573?file=%2Fsrc%2FApp.vue

Steps to reproduce the bug

1- click on "names query 1" 2- check logs 3- click on "names query 2" 4- check logs

Expected behavior

I expected that no log would be displayed after clicking on "names query 2".

Actual behavior

In fact, it seems that the entire query element is watched, not the names element itself

Additional information

No response

posva commented 7 months ago

Vue does some optimizations in watchers to avoid rerunning with the same value. In your case you have an array, so they are always different: [] !== []. Using a string or a computed of a string could help you achieve what you want.