What problem does it solve?
This guide removes ambiguity and fragile patterns when combining TanStack Query with TanStack Router and TanStack Start by prescribing how to coordinate caching, loaders, SSR hydration, and type-safe data fetching so applications avoid duplicate caches, loading waterfalls, and broken SSR hydration.
Core Features & Use Cases
- Router + Query Context: Pass a per-request QueryClient through the router context to enable SSR, testing, and type-safe loader access.
- Loader + ensureQueryData Pattern: Use loaders to prefetch via ensureQueryData so components can use useSuspenseQuery without loading waterfalls.
- Caching Coordination: Disable router cache (defaultPreloadStaleTime: 0) and let QueryClient manage staleTime, gcTime, and invalidation.
- SSR Dehydrate/Hydrate: Integrate setupRouterSsrQueryIntegration to automate dehydration, streaming, redirects, and client hydration.
- Use Case: Preload multiple queries in parallel for dashboards, ensure detail pages are fully cached before render, and perform mutation invalidation that reliably updates route state.
Quick Start
Configure your getRouter() to create a per-request QueryClient, pass it via router context, set defaultPreloadStaleTime to 0, and call setupRouterSsrQueryIntegration to enable automatic SSR dehydration and hydration.