这样写全局守卫跳转登陆:
router.beforeEach((to, from, next) => {
  // to and from are both route objects
  let isLogin = false
  if (isLogin) {
    next()
  } else {
    next({
      path: '/login',
      query: {redirect: to.fullPath}
    })
  }
})
报错 [vue-router] uncaught error during route navigation:
<failed to convert exception to string>
陷入了死循环,采用下面的写法就可以正常解析了,isLogin可以根据后台传递的变量存入Vuex中来管理
router.beforeEach((to, from, next) => {
  // to and from are both route objects
  let isLogin = false
  let path = to.path
  if (path === '/login') {
    next()
    return
  }
  if (isLogin) {
    next()
  } else {
    next({
      path: '/login',
      query: to.fullPath
    })
  }
})