You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add detailed Router caching example with loaderDeps
- Explain how Router automatically caches loader data by route + params
- Add loaderDeps example showing search param dependencies in cache key
- Show navigation flow and cache hit/miss behavior
Navigate from `/posts/abc` to `/posts/xyz` and the loader runs again because `$postId` changed. Navigate back to `/posts/abc` and Router serves the cached server component instantly (within the default `gcTime`).
189
+
190
+
For dependencies beyond route params, use `loaderDeps` to include search params or other reactive values in the cache key:
Now the cache key includes both the route param and search params. Change `?tab=comments` to `?tab=related` and the server component refetches. Change back and you get a cache hit.
212
+
213
+
**Router handles this automatically.** No manual cache keys, no query configuration. The server component is fetched when dependencies change and cached when they don't.
214
+
186
215
### With Query caching
187
216
188
217
Because server components are just data, they integrate naturally with TanStack Query's caching model. The query key determines cache identity—include route params and the cache automatically invalidates when they change:
0 commit comments