组合API中使用onBeforeRouteUpdate和onBeforeRouteLeave触发时机 #1837
-
Reproductionnone Steps to reproduce the bugimport { onBeforeRouteUpdate,onBeforeRouteLeave } from 'vue-router';
// 不同级的路由不能触发,如/operation/gift/material=>/log/index
onBeforeRouteUpdate(to => {
setTags(to);
});
// 同级别路由不能触发,如/operation/ToppingRoom=>/operation/sticker/material
onBeforeRouteLeave((to,from)=>{
// console.log(to,'onBeforeRouteLeave');
// console.log(from,'onBeforeRouteLeave');
setTags(to);
}) Expected behavior路由改变了,就能触发导航守卫 Actual behavioronBeforeRouteUpdate在形如/operation/gift/material=>/log/index的跨级别路由不能触发守卫 Additional informationNo response |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Jun 5, 2023
Replies: 1 comment
-
This is the intended behavior of these guards: https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#%E5%8F%AF%E7%94%A8%E7%9A%84%E9%85%8D%E7%BD%AE-api You can use a global navigation guard instead |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the intended behavior of these guards: https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#%E5%8F%AF%E7%94%A8%E7%9A%84%E9%85%8D%E7%BD%AE-api
You can use a global navigation guard instead
router.beforeResolve()
or an after hookrouter.afterEach()