浏览代码

添加错误更新

lex 1 年之前
父节点
当前提交
37a3b2b987
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      src/router/index.ts

+ 12 - 0
src/router/index.ts

@@ -90,4 +90,16 @@ const router: Router = createRouter({
   }
 });
 
+router.onError(error => {
+  if (error instanceof Error) {
+    const isChunkLoadFailed = error.name.indexOf('chunk');
+    const targetPath = router.currentRoute.value.fullPath;
+    console.log(error);
+    if (isChunkLoadFailed) {
+      location.hash = targetPath;
+      window.location.reload();
+    }
+  }
+});
+
 export default router;