T
TanStack•8mo ago
graceful-beige

how to navigate to dynamic route using hard-coded path?

This is the route blogs/$id and I wanna navigate to /blogs/1 when I did this navigate({ to: '/blogs/1',}); I get error
Type '"/blogs/1"' is not assignable to type '"/" | "." | ".." | "/about" | "/blog/$blogId" | "/blogs/$id"'.
Type '"/blogs/1"' is not assignable to type '"/" | "." | ".." | "/about" | "/blog/$blogId" | "/blogs/$id"'.
6 Replies
absent-sapphire
absent-sapphire•8mo ago
navigate({ to: '/blogs/$id', params: { id: 1 } })
graceful-beige
graceful-beigeOP•8mo ago
Okay that work. Also how do I deal with this "/blogs/$id?tag=$tag" it could have query param. I did not find in the doc how to construct for optional query param.
navigate({
to: '/blogs/$id?tag=$tag',
params: { id: '1' },
search: { tag: tag },
});
navigate({
to: '/blogs/$id?tag=$tag',
params: { id: '1' },
search: { tag: tag },
});
šŸ‘† getting error Also how to force rebuilt routeTree.gen.ts sometimes I get error there and either I have to delete the file or I have to manually edit (which is forbidden), in case it generates wrong file for my mistake.
absent-sapphire
absent-sapphire•8mo ago
Search Params | TanStack Router React Docs
Similar to how TanStack Query made handling server-state in your React applications a breeze, TanStack Router aims to unlock the power of URL search params in your applications. Why not just use URLSe...
absent-sapphire
absent-sapphire•8mo ago
you need a validateSearch function for your route i believe
graceful-beige
graceful-beigeOP•8mo ago
navigate('/path', {
search: {
userId: '123',
filter: 'active'
}
})
navigate('/path', {
search: {
userId: '123',
filter: 'active'
}
})
Never mind Claude gave me right answer I should only provide search object.
absent-sapphire
absent-sapphire•8mo ago
not if you also need params

Did you find this page helpful?