解决方法: 运用vue-router的错误处理函数 onError 捕获错误,代码如下:
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);
}
})
注:pattern 具体内容看自己的报错信息
