vue-router.esm.js?fe87:16 [vue-router] uncaught error during route navigation:
发生错误的代码:routerMap.beforeEach((to,from,next) => {const token = Cookies.get("token");if(!token){//未登录,强制登录next({name:"login"// 将跳转的路由pa
·
发生错误的代码:
routerMap.beforeEach((to,from,next) => {
const token = Cookies.get("token");
if(!token){//未登录,强制登录
next({
name:"login" // 将跳转的路由path作为参数,登录成功后跳转到该路由
});
}else{
next();
}
});
错误截图:
router.beforeeach Maximum call stack size exceeded
解决方案:
根据报错信息,得知:这段代码进入了dead loop。
To prevent the dead loop, just add a check :
routerMap.beforeEach((to,from,next) => {
const token = Cookies.get("token");
if(!token && to.path != '/login'){//未登录,强制登录
next({
name:"login" // 将跳转的路由path作为参数,登录成功后跳转到该路由
});
}else{
next();
}
});
更多推荐
已为社区贡献2条内容
所有评论(0)