T
TanStack14mo ago
other-emerald

How to use params.parse?

Before deprecation of parseParams, I used to do
export const Route = createFileRoute('/post/$id/_layout')({
component: Outlet,
parseParams: ({ id }) => {
if (/^\d+$/.test(id)) {
return { id: Number(id) };
}
throw new Error('Invalid ID: must be an integer');
},
});
export const Route = createFileRoute('/post/$id/_layout')({
component: Outlet,
parseParams: ({ id }) => {
if (/^\d+$/.test(id)) {
return { id: Number(id) };
}
throw new Error('Invalid ID: must be an integer');
},
});
Couldn't figure out how to implement the same behaviour with parse.params method.
2 Replies
national-gold
national-gold14mo ago
it's params.parse and, I guess, it should work the same you need to set
params: {
parse: (params) => {
// your logic
},
stringify: (params) => {
// your logic
}
}
params: {
parse: (params) => {
// your logic
},
stringify: (params) => {
// your logic
}
}
other-emerald
other-emeraldOP14mo ago
Thanks!

Did you find this page helpful?