router-core/data-loading

Implement TanStack Router data-loading patterns with loaders, loaderDeps, and deferred loading.

14.9k|1.8k|Updated Jan 14, 2019
One-click install
npx skills add https://github.com/TanStack/router --skill router-core-data-loading
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core/data-loading
Source: https://github.com/TanStack/router/tree/main/packages/router-core/skills/router-core/data-loading
Command: npx skills add https://github.com/TanStack/router --skill router-core-data-loading

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Data-loading patterns in TanStack Router can be verbose and error-prone without a structured guide that explains how to combine loaders, cache keys (loaderDeps), and deferred loading in real-world apps.

Core Features & Use Cases

  • Loader usage with params, deps, and context
  • loaderDeps for cache keys and dependent search params
  • Default SWR-like caching with staleTime, preloadStaleTime, and gcTime
  • Pending states, error handling, and beforeLoad/context
  • Deferred data loading with Await integration
  • createRootRouteWithContext factory pattern for typed context

Quick Start

Create a sample route using createFileRoute with a loader, a loaderDeps, and an optional pendingComponent to observe loading behavior.

Frequently Asked Questions about router-core/data-loading

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement data loading with TanStack Router loaders?

To implement data loading with TanStack Router, define a loader function on your route using createFileRoute, returning data for the component. You can access route params, dependencies, and context inside the loader function to fetch required data before rendering.

What is loaderDeps used for in TanStack Router?

loaderDeps in TanStack Router is used to generate cache keys based on dependent search params. By specifying loaderDeps, you control when the router should refetch data versus serving cached results when search parameters change.

How does caching work by default in TanStack Router data loading?

TanStack Router applies SWR-like caching defaults out of the box. It uses staleTime, preloadStaleTime, and gcTime configurations to manage cache freshness and garbage collection, reducing unnecessary refetches during navigation.

Can I defer data loading and show a pending state in TanStack Router?

Yes, you can defer data loading in TanStack Router by returning a promise from your loader. The route can display an optional pendingComponent while waiting, and the Await integration handles rendering the resolved deferred data.

How do I type context for beforeLoad and loaders in TanStack Router?

To type context in TanStack Router, use the createRootRouteWithContext factory pattern. This allows you to define a strongly typed context object that is passed into your route's beforeLoad and loader functions for safe data access.

How do I handle errors during data loading in TanStack Router?

TanStack Router provides built-in error handling for data loading. If a loader fails, the error is caught and can be managed using error boundaries or errorComponent configurations on the route, preventing the application from crashing.