T
TanStack•5mo ago
eager-peach

Is there a lifecycle hook that runs before validateSearch?

Two scenarios: 1. Page with required params, but the params can only be validated asynchronously, or have asynchronous fallback values. Right now we're abusing the layout route (or root in this case specifically) to do the search sanitation in beforeLoad, so the route can run its validateSearch on proper values. It feels very dirty and constraining. 2. Page with a guard based on search params. Do not allow entering page A without certain params set, if they are missing - redirect to page B. Since validateSearch cannot throw redirect AND it also runs before beforeLoad, we have to do the same layout (or root) shenanigans. Both scenarios could be solved easily if we had another lifecycle method that runs before validateSearch. What do you think? The alternative is to allow validateSearch to be async and allow throwing redirects, but that can be hard or even out of scope.
3 Replies
exotic-emerald
exotic-emerald•5mo ago
right now we don't have that. can you please describe your workaround using code examples in a github discussion feature request ?
eager-peach
eager-peachOP•5mo ago
will do 🫡
eager-peach
eager-peachOP•5mo ago
GitHub
Lifecycle hook that runs before validateSearch · TanStack router ...
copy-pasted from discord thread Two scenarios: Page with required params, but the params can only be validated asynchronously, or have asynchronous fallback values. Right now we're abusing the ...

Did you find this page helpful?