Closed minhtien020900 closed 10 months ago
Thanks for the great reproduction! The behavior you are seeing isn't related to the router, it's just how things work with Suspense (and in JS in general). The watcher being immediate, executes even though the component never manages to mount (it doesn't even unmount). The solution is to move the watcher within an onMounted()
to ensure this only runs if the component ever mounts
Reproduction
https://stackblitz.com/edit/vitejs-vite-zjpnie?file=src%2Fcomponents%2FHome.vue
Steps to reproduce the bug
Expected behavior
Actual behavior