修复学习流程路由切换与计时展示稳定性

This commit is contained in:
2026-04-12 13:05:23 +08:00
parent cef3192ba5
commit c84d30e287
4 changed files with 595 additions and 229 deletions
+14 -1
View File
@@ -1,4 +1,5 @@
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
import StartTask from "@/components/StartTask.vue";
const routes: RouteRecordRaw[] = [
{
@@ -17,6 +18,7 @@ const routes: RouteRecordRaw[] = [
},
{
path: "/study",
name: "study",
component: () => import("@/components/Study.vue"),
meta: { requiresAuth: true },
},
@@ -28,7 +30,7 @@ const routes: RouteRecordRaw[] = [
{
path: "/start-task/:taskNum",
name: "start-task",
component: () => import("@/components/StartTask.vue"),
component: StartTask,
meta: { requiresAuth: true },
},
{
@@ -58,6 +60,17 @@ const router = createRouter({
routes,
});
router.onError((error, to) => {
const message = String((error as Error)?.message || "");
const isChunkLoadError =
message.includes("Failed to fetch dynamically imported module") ||
message.includes("Importing a module script failed") ||
message.includes("Loading chunk");
if (isChunkLoadError && typeof window !== "undefined") {
window.location.assign(to.fullPath);
}
});
router.beforeEach((to) => {
if (to.meta.requiresAuth === false) return true;
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";