T
TanStack11mo ago
sunny-green

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
continuing-cyan
continuing-cyan11mo 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
}
}
sunny-green
sunny-greenOP11mo ago
Thanks!

Did you find this page helpful?