[vue-router] uncaught error during route navigation:

router.beforeEach((to, from, next) => {
    // 未登陆时,中断当前导航,跳转到登录页面
    if (!localStorage.getItem('mobile')) {
        next({
            replace:true,
            name:'login.index'
        });
    } else {
        next();
    }
});
复制代码

根据报错信息,得知:这段代码进入了死循环,解决方案bash

router.beforeEach((to, from, next) => {
    // 未登陆时,中断当前导航,跳转到登录页面
    if (!localStorage.getItem('mobile') && to.name != 'login.index') { // 排除要跳转的页面
        next({
            replace:true,
            name:'login.index'
        });
    } else {
        next();
    }
});
复制代码
相关文章
相关标签/搜索