vue-router.esm.js?9bfb:2085 Uncaught (in promise) undefined

路由无法重定向,这个报错请问怎么解决呢?不明白

阅读 5.3k
3 个回答

你这样问问题谁能帮你忙?就好像有地方着火了你报警说着火了又不说在什么地方一样

//在路由跳转之前判断,除了首页以外,其他页面必须登录才能访问,异步问题
router.beforeEach((to, from, next) => {

if (to.path \=== '/' || to.path \=== '/login') {  
    next();  

} else {

    axios.get("/user/isLogin")  
        .then(response => {  
            console.log(response.data);  

let data = response.data;
if (data.status === global.responseCode.OK && data.result === true) {

                console.log("登录成功");  

next();
} else {

                next('/login?redirect=' \+ to.path);  

}

        });  

}
});

新手上路,请多包涵

遇到了同样问题,请问解决了没?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题