问题描述
偶现路由切换,控制台报错 ChunkLoadError: Loading chunk {n} failed.

问题分析
可能是远程资源更新,浏览器缓存,出现静态资源不一致等原因造成的

简易版解决办法

router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
})

原文链接:https://blog.csdn.net/m0_37805167/article/details/130963928

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐