修复学习流程路由切换与计时展示稳定性
This commit is contained in:
+14
-1
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user