T
TanStack8mo ago
deep-jade

Redirect to throws type error on dynamic route

I have a dynamic route setup and the types keep throwing me errors even tho the route is clearly there.
export const Route = createFileRoute("/doc/$exportId")({
loader: async ({ params: { exportId } }) => {
redirect({
to: `/file/externalName/${exportId}`,
throw: true,
})
},
})
export const Route = createFileRoute("/doc/$exportId")({
loader: async ({ params: { exportId } }) => {
redirect({
to: `/file/externalName/${exportId}`,
throw: true,
})
},
})
The "to" keeps yelling at me that it is not a valid route, even tho I have "$sourceExternalName.$exportId.tsx" in my routes/file. Any idea why this could be?
1 Reply
yappiest-sapphire
yappiest-sapphire8mo ago
in tanstack/router, you shouldn't do the interpolation yourself. Your redirection should probably be something like
redirect({
to: '/file/externalName/$exportId',
params: { exportId },
throw: true
})
redirect({
to: '/file/externalName/$exportId',
params: { exportId },
throw: true
})
The to string should match a known route from the router, and this is how type-safety is handled

Did you find this page helpful?