Redirected when going from "/a" to "/b" via a navigation guard

如题,vue报错:

Uncaught (in promise) Error: Redirected when going from "/home" to "/user" via a navigation guard.

我的实际代码:

router.beforeEach((to, from, next) => {
    const meta = to.meta ? to.meta : {}
    const permission = meta.permission ? meta.permission : []
    const hasLogin = !localStorage.login_token && to.path !== '/' && permission.includes('login')
    if (hasLogin) {
      next('/login')
    } else {
      next()
    }
})
阅读 6.3k
1 个回答
router.beforeEach((to, from, next) => {
    const meta = to.meta ? to.meta : {}
    const permission = meta.permission ? meta.permission : []
    const hasLogin = !localStorage.login_token && to.path !== '/' && permission.includes('login')
    if (hasLogin) {
      // next('/login')
      router.push('/login')
    } else {
      next()
    }
})
推荐问题