zhuangyunsheng 1 år sedan
förälder
incheckning
ef79816a9e
1 ändrade filer med 7 tillägg och 4 borttagningar
  1. 7 4
      src/router/index.js

+ 7 - 4
src/router/index.js

@@ -170,11 +170,14 @@ router.afterEach((to, from) => {
 });
 
 router.onError((error) => {
+    console.log('routerError:message', error.message)
+    console.log('routerError:targetPath', router.history.pending.fullPath)
     NProgress.done();
-    ElNotification.error({
-        title: "路由错误",
-        message: error.message
-    });
+    const pattern = /Loading chunk (\d)+ failed/g;
+    const isChunkLoadFailed = error.message.match(pattern);
+    const targetPath = router.history.pending.fullPath;
+    if (isChunkLoadFailed) router.replace(targetPath);
+    else ElNotification.error({ title: "路由错误", message: error.message });
 });
 
 // 生成路由对象