vue 项目中跳转不存在的路由


在项目中遇到这么一个需求,登录页面跳转不存在的路由都重新指向登录页面,但是loginNocode页面除外,要跳转loginNocode,

登陆之后跳转不存在的路由的时候跳转404页面

我是在main.js中的router.beforeEach写的。中心代码如下:

if (!tokenStr){
    if (to.path!='/loginNocode') return next('/')
  }else{
    // console.log(to.path.slice(1),'====',to.matched,'111111111',from)
    if(to.matched.length == 0) return next('/error')
    if(to.path.slice(1) == 'error'){
      store.state.fourErrorNavShow = false
    }else{
      store.state.fourErrorNavShow = true
    }
  };

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM