Vue中的keep-alive不能缓存二级以上路由的解决办法

261 阅读1分钟

keep-alive的include可以加上组件name来缓存路由,但是缓存不了二级以上的路由

在路由拦截器中写上这几行代码,就能完美解决了

QQ图片20220525220232.png

if (to.matched && to.matched.length > 2) {
      to.matched.splice(1, to.matched.length-2)
 }