如果出现了该提示错误,浏览器前进后退按钮都不可用了,必须要点击刷新按钮页面才能正常加载
如图所示:
通过查看vue-router文档有一个router.onError的回调函数:原理就是在监听到路由报错信息后自动进行页面刷新,获取最新的代码。
具体方法在router目录下的index.js文件中添加代码如下:
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)
}
})
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。