在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ vue failed to convert exception to strin

vue failed to convert exception to string

使用了vue的導(dǎo)航守衛(wèi)之后就報(bào)錯(cuò)

failed to convert exception to string
router.beforeEach(function(to, from, next){
    /* 路由發(fā)生變化修改頁(yè)面title */
    if (to.meta.title) {
        document.title = to.meta.title
    }
    if(!localStorage.getItem('token')){
        // router.push({name:'login'})
        // router.push({name: 'login'});
        next({ path: '/user/login' });
    }
    next();
});
export default router;
回答
編輯回答
尛曖昧

你這樣寫(xiě)會(huì)陷入無(wú)限循環(huán)的,給你個(gè)參考下

let login = localStorage.getItem('token')
let path = to.path
if (path === '/user/login') {
  next()
  return
}
if (login) {
  if (path === '/') {
    next({
      path: '/index'
    })
  } else {
    next()
  }
} else {
  next({
    path: '/user/login'
  })
}
2017年5月6日 21:33