TanStack Router has a built-in per-route cache, but TanStack Query's global QueryCache is better suited for data shared across multiple routes. The post explains why using route loaders to prefetch queries (without awaiting) is a best practice, how to wire up the queryClient in router context, and why components should use useQuery or useSuspenseQuery instead of useLoaderData. It also covers disabling the router's own caching when Query is in charge, the decision between blocking and deferred data loading, and how the integration extends to TanStack Start with SSR streaming that seeds the client-side QueryCache automatically.
Table of contents
Combining Query and RouterAdd the QueryClient to the Router ContextuseQuery or useSuspenseQuery ?To await or not to await in the loaderAlways use a QueryTreat the loader as an event handlerContinue Series140.7K Impressions3 Comments