Nested optional path params? (Google Calendar-style routing problem) #3818
-
I'm migrating my app from Next.js to Vite + Tanstack Router and I'm struggling to conceptualize this requirement for my calendar feature. The app needs to support nested routes of the form: /calendar/$view/$y/$m/$d where
I've tried using Just to add a bit more clarity, here are the typedefs I'm trying to enforce: enum View {
YEARLY = 'y',
MONTHLY = 'm',
WEEKLY = 'w',
}
interface CalendarParams {
view: View
y?: string;
m?: string;
d?: string;
}
type WeeklyParams = CalendarParams & {
view: View.WEEKLY;
}
type MonthlyParams = Pick<CalendarParams, 'view' | 'y' | 'm'> & {
view: View.MONTHLY
}
type YearlyParams = Pick<CalendarParams, 'view' | 'y'> & {
view: View.YEARLY
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think I've managed to implement a reasonable solution here 🙌 Will post my code before closing this discussion. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
https://github.com/curtisupshall/zisk/blob/32eec1109871a92513a514f18f90e9e907264817/app/src/web/routes/_mainLayout/journal.%24view.%24.tsx