Uh oh!
There was an error while loading. Please reload this page.
Deterministic way to gate navigation on preload success? #7002
Replies: 2 comments 3 replies
Hey @tannerlinsley@schiller-manuel , |
This is documented, just not obviously discoverable from the API reference alone. import{isNotFound}from'@tanstack/react-router'constmatches=awaitrouter.preloadRoute({to: postRoute,params: {id: 1}})constrouteFailure=matches?.find((match)=>match.status==='error'||match.status==='notFound'||isNotFound(match.error),)if(routeFailure){// inspect routeFailure.error}Combined with So the deterministic gate you're after is: |
Uh oh!
There was an error while loading. Please reload this page.
Hi folks, we are working through a checkout-style flow and wanted to check if there is an intended pattern for this.
Our goal is:
We found that the immediate enter refetch is handled by setting a staleTime, so that part is OK.
What we are still missing is a deterministic success or failure signal from preloadRoute() itself.
staleReloadMode: blocking helps because preload waits for the loader promise to settle, but if the loader throws, preloadRoute() seems to return undefined, and we could not find a clean API to know whether route B loader actually succeeded or failed before deciding to navigate.
Is there a first-class TanStack Router way to gate navigation on preload success, without directly calling route B fetcher outside the loader?
All reactions