当前位置: 代码迷 >> 综合 >> 解决element-ui.common.js?5c96:3:Navigation cancelled from “/admin“ to “/users“ with a new navigation.
  详细解决方案

解决element-ui.common.js?5c96:3:Navigation cancelled from “/admin“ to “/users“ with a new navigation.

热度:86   发布时间:2023-12-05 01:45:18.0

当我在写电商管理系统时,点击菜单栏进行路由跳转时,报一个关于路由的错误

element-ui.common.js?5c96:3374 Error: Navigation cancelled from "/admin" to "/users" with a new navigation.
    at createRouterError (vue-router.esm.js?8c4f:2065)
    at createNavigationCancelledError (vue-router.esm.js?8c4f:2047)
    at eval (vue-router.esm.js?8c4f:2399)
    at step (vue-router.esm.js?8c4f:2001)
    at step (vue-router.esm.js?8c4f:2008)
    at runQueue (vue-router.esm.js?8c4f:2012)
    at eval (vue-router.esm.js?8c4f:2397)
    at step (vue-router.esm.js?8c4f:2001)
    at eval (vue-router.esm.js?8c4f:2005)
    at eval (vue-router.esm.js?8c4f:2384)

解决方案

//路由导航守卫
router.beforeEach((to, from, next) => {//判断是否是登录页,如果是接着下一步if (to.path === '/login') return next()//    获取tokenconst tokenStr = window.sessionStorage.getItem('token')//判断token是否存在,if (!tokenStr) {return next('/login')}next()
})

 

检查自己在写导航守卫时最后是否多加了一个next(),只需要去掉一个next()即可 

  相关解决方案