这个在网上有很多解决方法
大部分这样的,
我发现当router为hash模式
router.history.pending.fullPath获取不到值
测试得知改成这样
router.history.current.fullPath
/**
* 解决偶尔出现Loading chunk {n} failed的报错
*/
router.onError((error) => {
console.error('路由异常', error)
const pattern = /Loading chunk (\d)+ failed/g
const isChunkLoadFailed = error.message.match(pattern)
const targetPath = router.history.current.fullPath
if (isChunkLoadFailed) {
router.replace(targetPath)
}
})