Lifecycle hook that runs before validateSearch #3977
KubaJastrz
started this conversation in
Ideas
Replies: 1 comment
-
One major drawback of my workaround with pathless routes is that you cannot have a We use this Example: https://stackblitz.com/edit/tanstack-router-tz426unm?file=src%2Froutes%2Fabout%2F_layout.tsx |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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 layout route to do the search sanitation in beforeLoad, so the route can run its validateSearch on proper values. It feels very dirty and constraining.
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 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.
Reproduction for workaround
My workarounds are reproduced here: https://stackblitz.com/edit/tanstack-router-btjaxn96?file=src%2Froutes%2F__root.tsx
_async
pathless route sets fallback values forparam
asynchronously, so that/async-params
route can set it as required_guard
pathless route ensures that you cannot enter/params-guard
withoutparam
, and so that/params-guard
can set it as requiredI also noticed two bugs with this repro, not sure if relevant (I forked the quickstart example from docs):
/async-params
route isn't matched as active in the header (works if I setexact: false
)It's possible that both of these problems are caused by my weird workarounds though 😅
Beta Was this translation helpful? Give feedback.
All reactions