diff --git a/src/views/studentDemo/index.vue b/src/views/studentDemo/index.vue index 3f4da12..b0d015b 100644 --- a/src/views/studentDemo/index.vue +++ b/src/views/studentDemo/index.vue @@ -19,7 +19,7 @@ function receiveTicket(event) { saveStudentDemoSession(res.data); window.clearInterval(readyTimer); window.removeEventListener("message", receiveTicket); - window.location.replace("/index"); + window.location.replace("/#/index"); }).catch(() => { message.value = "演示链接已失效,请返回教师端重新打开。"; }); } diff --git a/src/views/teacherEnd/trainingTask/index.vue b/src/views/teacherEnd/trainingTask/index.vue index 75239c8..ce22ed1 100644 --- a/src/views/teacherEnd/trainingTask/index.vue +++ b/src/views/teacherEnd/trainingTask/index.vue @@ -578,7 +578,7 @@ async function restoreAllTasksDefaults() { async function openStudentDemo() { if (!selectedTeachingClass.value) return; - const child = window.open("/student-demo", "_blank"); + const child = window.open("/#/student-demo", "_blank"); if (!child) { proxy?.$modal?.msgError?.("浏览器拦截了演示窗口,请允许弹窗后重试"); return; } let ticket = ""; let childReady = false; diff --git a/tests/student-demo-hash-routing.test.mjs b/tests/student-demo-hash-routing.test.mjs new file mode 100644 index 0000000..434eaaa --- /dev/null +++ b/tests/student-demo-hash-routing.test.mjs @@ -0,0 +1,12 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; + +const root = resolve(import.meta.dirname, ".."); +const teacherTaskPage = readFileSync(resolve(root, "src/views/teacherEnd/trainingTask/index.vue"), "utf8"); +const studentDemoPage = readFileSync(resolve(root, "src/views/studentDemo/index.vue"), "utf8"); + +assert.match(teacherTaskPage, /window\.open\("\/#\/student-demo", "_blank"\)/, "学生端讲解必须通过 Hash 路由打开演示入口"); +assert.match(studentDemoPage, /window\.location\.replace\("\/#\/index"\)/, "兑换演示学生会话后必须通过 Hash 路由进入学生首页"); + +console.log("student demo uses hash routes instead of falling back to the teacher homepage");