美文网首页
2021-08-20动态增加路由

2021-08-20动态增加路由

作者: 0说 | 来源:发表于2021-08-20 11:32 被阅读0次
import router from './router'
router.beforeEach(async (to, from, next) => {

      if (to.path === '/login') {
        next({
          name: 'default'
        })
      } else {
        console.log(router.options.isAdd)
        if (!router.options.isAdd) {
            
          router.addRoutes([
            {
                path: '/plan',
                name: 'plan',
                component:() => import('@/views/Plan.vue') 
            },
            {
                path: '/planB',
                name: 'planB',
                component:() => import('@/views/PlanB.vue')  
            }
          ])
          console.log(router)
          router.options.isAdd = true
          console.log(to.path)
        // 确保路由添加完成
          next({
            ...to,
            replace: true
          })
          
        } else {
            next()
        }
        // next()
      }
  })

相关文章

网友评论

      本文标题:2021-08-20动态增加路由

      本文链接:https://www.haomeiwen.com/subject/hpctiltx.html