tanstack-router-best-practices

Implement TanStack Router architecture with typed routes, loaders, and preloading.

2.5k|134|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/compozy/compozy --skill tanstack-router-best-practices-compozy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-router-best-practices
Source: https://github.com/compozy/compozy/tree/main/.agents/skills/tanstack-router-best-practices
Command: npx skills add https://github.com/compozy/compozy --skill tanstack-router-best-practices-compozy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Router best practices help developers implement type-safe, scalable routing patterns in React applications, reducing boilerplate and navigation errors.

Core Features & Use Cases

  • Type-safe routing and loaders: enforce precise types across routes, loaders, and params.
  • Efficient data loading: guide parallel loading, preloading, and cache-aware data fetching with TanStack Query integration.
  • Robust routing organization: guidance on route structure, code-splitting, and error handling for complex apps.
  • Practical usage scenarios: when to apply root vs lazy routes, notFound handling, and search params validation.

Quick Start

Use the TanStack Router best practices to organize a React app with typed routes, loaders, and preloading.

Frequently Asked Questions about tanstack-router-best-practices

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

FAQPage Schema
How do I implement type-safe routing and loaders in a React application?

Type-safe routing in React is implemented by registering typed routes via ts-register-router, enforcing precise types across routes, params, and loaders to reduce boilerplate and navigation errors. This architecture ensures compile-time validation for complex navigation scenarios.

What's the best way to handle parallel data loading and preloading with TanStack Router?

Parallel data loading with TanStack Router is handled using Promise.all for concurrent fetching, while preloading and cache-aware data fetching are managed through TanStack Query integration with ensureQueryData to cache loader data efficiently.

How do I structure root versus lazy routes and handle code-splitting in React?

Route structure and code-splitting in React are organized by applying root versus lazy routes based on navigation complexity, implementing appropriate defaults and fallbacks, and using notFound handling and search params validation for robust routing organization.

Does TanStack Router work with TanStack Query for data fetching and caching?

TanStack Router works with TanStack Query to provide cache-aware data fetching, utilizing ensureQueryData for loader data caching and integrating parallel data loading with Promise.all to optimize fetching across complex navigation scenarios.

How do I handle errors and notFound components in type-safe React routes?

Error handling and notFound components in type-safe React routes are handled by applying guidance on route structure with appropriate fallbacks, using notFound handling for missing paths, and validating search params to prevent navigation errors.