Vue Router warn The “next“ callback was called more than once in one navigation guard
问题:问题代码:router.beforeEach(async (to, from, next) => {const token = Cookies.get('token');next();if (to.path === '/login' || to.path === '/') {next();}else {if (token) {next();} else {
·
问题:
问题代码:
router.beforeEach(async (to, from, next) => {
const token = Cookies.get('token');
next();
if (to.path === '/login' || to.path === '/') {
next();
}
else {
if (token) {
next();
} else {
console.log('pms out');
next('/login');
}
}
})
问题点:
这个是路由导航next函数执行了两次,所以我们要检查下router.beforeEach
修改后的代码
router.beforeEach(async (to, from, next) => {
const token = Cookies.get('token');
if (to.path === '/login' || to.path === '/') {
next();
}
else {
if (token) {
next();
} else {
console.log('pms out');
next('/login');
}
}
})
就是把多余的next()
删除
更多推荐
已为社区贡献4条内容
所有评论(0)