You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #2504 on May 27, 2025 13:30.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
4.*
Steps to reproduce the bug
在选项式的页面中注册页面的子组件中调用守卫事件beforeRouteLeave
但是在声明式的页面中的子组件调用onBeforeRouteLeave就可以
Expected behavior
在注册页面的子组件中调用守卫事件生效
Actual behavior
在注册页面的子组件中调用守卫事件不生效
Additional information
排查源码发现问题在于选项式的守卫事件只是直接调用了 component 的 守卫事件方法 而这种方式无法对组件中的子组件进行扫描
但是在声明式中是把onBeforeRouteLeave直接注册成了事件 是组件主动调用的 而不是 vue-router 自动获取的 目前的解决办法是在 vue 的 created 或 mounted生命周期中调用onBeforeRouteLeave 手动注册事件
希望可以更新文档或使用其他方式扫描选项式的守卫事件
Beta Was this translation helpful? Give feedback.
All reactions