diff --git a/src/pages/exam-detail-page.tsx b/src/pages/exam-detail-page.tsx index 46e9a60..cdb8c3b 100644 --- a/src/pages/exam-detail-page.tsx +++ b/src/pages/exam-detail-page.tsx @@ -62,7 +62,12 @@ function ExamDetailContent() { const t = useT(); const { locale } = usePreferences(); const now = createNow(); - const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? "")); + // Keep the previous id while navigating away, so the resource does not + // fetch the next page's path segment (e.g. GET /exams/exams) mid-transition. + const id = createMemo((prev: string) => { + const match = /^\/exams\/([^/]+)$/.exec(location().pathname); + return match ? decodeURIComponent(match[1]) : prev; + }, ""); const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId)); const [settings] = createResource(() => getSettings()); diff --git a/src/pages/exam-room-page.tsx b/src/pages/exam-room-page.tsx index 927e1ec..d35dfe2 100644 --- a/src/pages/exam-room-page.tsx +++ b/src/pages/exam-room-page.tsx @@ -25,7 +25,12 @@ function ExamRoomContent() { const location = useLocation(); const auth = useAuth(); const t = useT(); - const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? "")); + // Keep the previous id while navigating away, so the resource does not + // fetch the next page's path segment (e.g. GET /exams/exams) mid-transition. + const id = createMemo((prev: string) => { + const match = /^\/exam-room\/([^/]+)$/.exec(location().pathname); + return match ? decodeURIComponent(match[1]) : prev; + }, ""); const [exam] = createResource(id, (examId) => getExamById(examId)); const [mine] = createResource( () => (auth.user()?.role === "student" ? true : null),