0
点赞
收藏
分享

微信扫一扫

Vue-route 的导航守卫

修炼之士 2023-05-19 阅读 27


全局前置守卫

const router = new VueRouter({ ... })

router.beforeEach((to, from, next) => {
  // ...
})

每个守卫方法接收三个参数:

  • to: Route: 即将要进入的目标 路由对象
  • from: Route: 当前导航正要离开的路由
  • next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。

全局后置钩子

router.afterEach((to, from) => {
  // ...
})


举报

相关推荐

0 条评论