vue-router 2.0.1钩子函数不能正常的跳转。

如题:

router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requiresAuth)) {
        next("/")
        console.log(1)
    }else {
        next()
    }
})

直接跳过了next("/")打印了1,不知是不是bug还是我的写法有问题。

阅读 4.7k
1 个回答
router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requiresAuth)) return next('/login')
    next()
  })
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题