1

如果出现了该提示错误,浏览器前进后退按钮都不可用了,必须要点击刷新按钮页面才能正常加载
如图所示:
image.png
通过查看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)
  }
})

fuGUI
1.7k 声望2.5k 粉丝

The best time to plant a tree is ten years ago, and the second,let us start