🐛 stop exam pages fetching junk ids while navigating away - anchor exam detail and exam room id parsing to their route shapes - keep the previous id during exit transitions instead of adopting the next page's last path segment - removes transient GET /exams/exams and GET /exams/events 404s on every navigation out of exam pages
Browse files at this commit42fe896d7c50677eb75a6988817be2cec52adcdaParent: 4aecb40- fix
- 🐛 stop exam pages fetching junk ids while navigating away - anchor exam detail and exam room id parsing to their route shapes - keep the previous id during exit transitions instead of adopting the next page's last path segment - removes transient GET /exams/exams and GET /exams/events 404s on every navigation out of exam pages
2 changed files +12 -2
src/pages/exam-detail-page.tsxmodified+6 -1
| @@ -62,7 +62,12 @@ function ExamDetailContent() { | ||
| 62 | 62 | const t = useT(); |
| 63 | 63 | const { locale } = usePreferences(); |
| 64 | 64 | const now = createNow(); |
| 65 | - const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? "")); | |
| 65 | + // Keep the previous id while navigating away, so the resource does not | |
| 66 | + // fetch the next page's path segment (e.g. GET /exams/exams) mid-transition. | |
| 67 | + const id = createMemo((prev: string) => { | |
| 68 | + const match = /^\/exams\/([^/]+)$/.exec(location().pathname); | |
| 69 | + return match ? decodeURIComponent(match[1]) : prev; | |
| 70 | + }, ""); | |
| 66 | 71 | |
| 67 | 72 | const [exam, { refetch: refetchExam }] = createResource(id, (examId) => getExamById(examId)); |
| 68 | 73 | const [settings] = createResource(() => getSettings()); |
src/pages/exam-room-page.tsxmodified+6 -1
| @@ -25,7 +25,12 @@ function ExamRoomContent() { | ||
| 25 | 25 | const location = useLocation(); |
| 26 | 26 | const auth = useAuth(); |
| 27 | 27 | const t = useT(); |
| 28 | - const id = createMemo(() => decodeURIComponent(location().pathname.split("/").pop() ?? "")); | |
| 28 | + // Keep the previous id while navigating away, so the resource does not | |
| 29 | + // fetch the next page's path segment (e.g. GET /exams/exams) mid-transition. | |
| 30 | + const id = createMemo((prev: string) => { | |
| 31 | + const match = /^\/exam-room\/([^/]+)$/.exec(location().pathname); | |
| 32 | + return match ? decodeURIComponent(match[1]) : prev; | |
| 33 | + }, ""); | |
| 29 | 34 | const [exam] = createResource(id, (examId) => getExamById(examId)); |
| 30 | 35 | const [mine] = createResource( |
| 31 | 36 | () => (auth.user()?.role === "student" ? true : null), |