vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

watch router or router.currentRoute.path question #3867

Closed Miofly closed 11 months ago

Miofly commented 11 months ago

in App.vue

route change watch not trgger

watch(()=> router.currentRoute.path, (val) => {\
    console.log('router.currentRoute.path not trigger', val);
}, {
  immediate: true
});

why oldValue === val

watch(()=> route, (val, oldValue) => {
    console.log('route.path not trigger', val, oldValue);
  console.log('why is true', JSON.stringify(val) === JSON.stringify(oldValue));
}, {
  immediate: true,
  deep: true
});

home.vue

onDeactivated(() => {
  console.log('onDeactivated why after onBeforeRouteLeave');
})

onBeforeRouteLeave((_, from, next) => {
  console.log('onBeforeRouteLeave');
  next()
})

why onDeactivated after onBeforeRouteLeave

repo link: https://github.com/Miofly/demo-issue-template/tree/vue2-template

posva commented 11 months ago

Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server or StackOverflow.

Miofly commented 11 months ago

watch(()=> route, (val, oldValue) => { console.log('route.path not trigger', val, oldValue); console.log('why is true', JSON.stringify(val) === JSON.stringify(oldValue)); }, { immediate: true, deep: true });

i think this question is bug, watch route old and new is equal? Because the above issue is no problem in vue-route4