Skip to content

Commit 0f1b413

Browse files
fix: correct year param parsing
1 parent 4cc08cb commit 0f1b413

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/app/_home/$school/$year/$id/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ function getCoursesMap(
114114
export const Route = createFileRoute("/_home/$school/$year/$id/")({
115115
params: {
116116
parse: ({ school, year, id }) => {
117-
if (isSchool(school)) return { school, year: parseInt(year, 10), id }
118-
else throw redirect({ to: "/" })
117+
if (!isSchool(school)) throw redirect({ to: "/" })
118+
119+
const yearInt = parseInt(year, 10)
120+
if (Number.isNaN(yearInt))
121+
throw redirect({ to: "/$school", params: { school } })
122+
123+
return { school, year: yearInt, id }
119124
},
120125
},
121126
loader: ({ params }) => {
@@ -194,13 +199,15 @@ function Component({ ranking }: { ranking: NewRanking }) {
194199

195200
return (
196201
<Page
197-
className={`flex items-center gap-4 px-0 ${isMobile ? "flex-col overflow-y-auto overflow-x-hidden" : ""
198-
}`}
202+
className={`flex items-center gap-4 px-0 ${
203+
isMobile ? "flex-col overflow-y-auto overflow-x-hidden" : ""
204+
}`}
199205
fullWidth
200206
>
201207
<div
202-
className={`flex w-full max-w-7xl flex-col gap-4 px-4 ${isMobile ? "flex-col overflow-y-auto overflow-x-hidden" : ""
203-
}`}
208+
className={`flex w-full max-w-7xl flex-col gap-4 px-4 ${
209+
isMobile ? "flex-col overflow-y-auto overflow-x-hidden" : ""
210+
}`}
204211
>
205212
<PathBreadcrumb />
206213
<div className="flex w-full gap-4 max-sm:flex-col sm:items-center">

src/app/_home/$school/$year/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ export const Route = createFileRoute("/_home/$school/$year/")({
1111
component: RouteComponent,
1212
params: {
1313
parse: ({ school, year }) => {
14-
if (isSchool(school)) return { school, year: parseInt(year, 10) }
15-
else throw redirect({ to: "/" })
14+
if (!isSchool(school)) throw redirect({ to: "/" })
15+
16+
const yearInt = parseInt(year, 10)
17+
if (Number.isNaN(yearInt))
18+
throw redirect({ to: "/$school", params: { school } })
19+
20+
return { school, year: yearInt }
1621
},
1722
},
1823
})

0 commit comments

Comments
 (0)