T
TanStack4mo ago
sunny-green

How to redirect and pass search params?

I have a legacy route that has to be redirected to a new route, and I need to pass all search params passed to that route, how do I achieve this using a zod validator?
4 Replies
adverse-sapphire
adverse-sapphire4mo ago
throw a redirect in its beforeLoad
equal-aqua
equal-aqua4mo ago
Oh, I have a similar case! I have legacy search params, and I want to remove them from the URL if they don’t pass up-to-date validation. Is it possible to trigger a redirect from validateSearch to do that? Or is there a better way?
sunny-green
sunny-greenOP4mo ago
Just doing a redirect removes all search params though
beforeLoad: () => {
throw redirect({
to: '/other-url',
search: prev => prev
});
}
beforeLoad: () => {
throw redirect({
to: '/other-url',
search: prev => prev
});
}
Does the trick
adverse-sapphire
adverse-sapphire4mo ago
search: true should work too

Did you find this page helpful?