vue验证登录(Detected an infinite redirection in a navigation guard when going from "/" to "/login". Aborting to avoid a Stack Overflow. This will break in production if not fixed.)

出现错误

提示信息:

router.beforeEach((to, from, next) => {
  if (!storage.getItem('userInfo')) {
    console.log('error')
    next({ path: '/login' })
  } else {
    console.log('ok')
    next()
  }
})

修改bug后

router.beforeEach((to, from, next) => {
  if (to.path === '/login')  next()
    if (!storage.getItem('userInfo')) {
      next({ path: '/login' })
    } else {
      console.log('ok')
      next()
    }
})
posted @ 2021-06-06 13:33  abcdefgab  阅读(9594)  评论(0)    收藏  举报