T
TanStack2y ago
old-apricot

How should I be expected to parse params ?

Hello there, I'm currently migrating one of our frontends to tsr from react-router. I would like to be able to parse the route's path params through a zod parser.
z.object({
systemId: systemId.optional(),
activityId: activityId.optional(),
})
z.object({
systemId: systemId.optional(),
activityId: activityId.optional(),
})
but when I try to:
const galaxyRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/galaxy/$systemId/$activityId",

parseParams: (params) =>
z.object({
systemId: systemId.optional(),
activityId: activityId.optional(),
})
.parse(params),

}).lazy(() => import("./pages/galaxy").then((d) => d.Route))
const galaxyRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/galaxy/$systemId/$activityId",

parseParams: (params) =>
z.object({
systemId: systemId.optional(),
activityId: activityId.optional(),
})
.parse(params),

}).lazy(() => import("./pages/galaxy").then((d) => d.Route))
I get an error:
parseParams must return an object
parseParams must return an object
What am I doing wrong here ? I didn't find too much documentation on the parseParams, no in code description too. If I'm able to parseParams should I not be allowed to transform it to something else ? PS: It seems to go away if I return some kind of record ?
3 Replies
unwilling-turquoise
unwilling-turquoise2y ago
is this a typescript or a runtime error?
old-apricot
old-apricotOP2y ago
typescript
unwilling-turquoise
unwilling-turquoise2y ago
can you please provide minimal complete example e.g. by forking one of the existing examples on Stackblitz?

Did you find this page helpful?