若依、vue三级路由缓存失败

发布时间 2024-01-03 15:29:19作者: xuelin
router.beforeEach((to, from, next) => {
  NProgress.start()
  if (getToken()) {
    // 三级菜单组件无法缓存问题
    if (to.matched && to.matched.length > 2) {
      to.matched.splice(1, to.matched.length - 2)
    }
   
    to.meta.title && useSettingsStore().setTitle(to.meta.title)
   
    } else {
      next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
      NProgress.done()
    }
  }
})