Loading chunk {n} failed问题

原文:https://segmentfault.com/a/1190000016382323

vue-router错误处理函数

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);
  }
});

 

posted @ 2021-09-01 17:13  xingba-coder  阅读(478)  评论(0编辑  收藏  举报