问题描述
偶现路由切换,控制台报错 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

一站式 AI 云服务平台

更多推荐