资讯详情

解决vue使用beforeEach路由导航守卫死循环

死循环版(错误示例):

router.beforeEach((to, from, next) => {   if(localStorage.getItem("token-xsm") != null) {     next();   }else {     next('/login')        } })

正确版本:

router.beforeEach((to, from, next) => {   if(localStorage.getItem("token-xsm") != null) {     next();   }else {     if(to.path == '/login'){       next()     }     else{       next('/login')     }   } })

总结: 首先要明白beforeEach该函数的运行机制是每次访问路由跳转时都要执行该钩函数 当token不存在时 跳转到登录页面,

标签: xsm吸收薄膜电容器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台