vue-router动态路由无限循环

// isLogined 用来判断用户是否已登录
router.beforeEach((to, from, next) => {
  if(isLogined){
    next()
  }else{
    console.log('测试')
    next('login')
  }
})


  • next() 表示放行,直接进入to路由,不会再次调用router.beforeEach()
  • next(path:...to,replace:true) 拦截路由,当条件成立时就会无限次放行,进入无限循环,必须要设置出口
  • next(path:'/') 当前路由被中断,进入一个新的导航  、需要加判断、不然会进入无限循环
  • 可以理解为
router.beforeEach((to, from, next) => {
  router.beforeEach((to, from, next) => {
    router.beforeEach((to, from, next) => {
    router.beforeEach((to, from, next) => {
      router.beforeEach((to, from, next) => {
         。。。
})
})
})
})
})
//必须要设置出口

router.beforeEach((to, from, next) => {
   let flag=true
    if(flag){
     //条件成立,放行并进入页面
    next()
    }else{
      //重载路由
      next({path:...to,replace:true})
    } })


posted @   绝版龙宝宝  阅读(376)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示