T
TanStack17mo ago
conscious-sapphire

Redirect from validateSearch to the same route with fixed query params using replace

Hi! We're currently using react-router, but we're investigating switching to this library. We're using query params quite heavily in our app and we'd like to be able to validate and fix them inside the router and not components, to avoid the initial render of a component with the invalid state. If the query params are not valid, is there a way to redirect from the router to the same route, but with updated query params, by replacing the invalid entry in the browser's history stack?
1 Reply
genetic-orange
genetic-orange17mo ago
Can this be the solution? https://tanstack.com/router/latest/docs/framework/react/guide/search-params#enter-validation--typescript Inside validateSearch you have full control of the params and you're free to edit/fix them before loading the route
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 URLSearchParams?

Did you find this page helpful?