tanstack-router

Implements type-safe routing for React applications with search params and data loading.

Updated Sep 17, 2026
One-click install
npx skills add https://github.com/juanjaragavi/utilities-manager --skill tanstack-router-juanjaragavi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tanstack-router
Source: https://github.com/juanjaragavi/utilities-manager/tree/main/.agents/skills/tanstack-router
Command: npx skills add https://github.com/juanjaragavi/utilities-manager --skill tanstack-router-juanjaragavi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router, @tanstack/router-plugin, @tanstack/router-cli, @tanstack/react-router-devtools.

What problem does it solve? Building React applications with routing often leads to runtime errors from untyped route params, scattered data-fetching logic in useEffect hooks, and fragile search parameter handling. This Skill provides the patterns and APIs to implement fully type-safe routing with TanStack Router, covering route trees, loaders, search validation, and navigation. ## Core Features & Use Cases - File-Based and Code-Based Routing: Define routes via file conventions (dynamic $param, pathless _layout, splat routes) or programmatic route trees with automatic type generation. - Type-Safe Data Loading: Use route loaders with loaderDeps, staleTime, deferred streaming via defer/Await, and TanStack Query integration through router context. - Search Param Validation & Navigation: Validate URL search params with Zod schemas, navigate with typed Link components or useNavigate, and guard routes with beforeLoad redirects. - Use Case: Build a dashboard where the posts list page validates ?page and ?filter search params, preloads data on link hover, blocks navigation away from dirty forms, and redirects unauthenticated users to login. ## Quick Start Ask the AI to set up TanStack Router in your React app with file-based routing, a posts route with a loader, and validated search parameters.

Frequently Asked Questions about tanstack-router

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

FAQPage Schema
How do I set up file-based routing with TanStack Router?▼

Install @tanstack/react-router and the @tanstack/router-plugin Vite plugin, then add TanStackRouterVite() to your Vite config. Files in your routes directory automatically generate the route tree using conventions like $param for dynamic segments and _prefix for pathless layouts.

How do I validate search params in TanStack Router?▼

Use the validateSearch option on a route with a Zod schema or a custom function that parses the raw search object. The validated result is fully typed and accessible via Route.useSearch() or useSearch({ from: routePath }).

Does TanStack Router work with TanStack Query?▼

Yes, pass the QueryClient through router context and call queryClient.ensureQueryData inside route loaders. Components can then use useSuspenseQuery with the same query options for reactive updates without refetching fresh data.

How do I protect routes with authentication in TanStack Router?▼

Use the beforeLoad hook on a pathless layout route like _authenticated to check auth state from router context and throw a redirect to the login page. This prevents protected content from rendering, unlike checks inside components.

Why is my TanStack Router loader not re-running when search params change?▼

Loaders only re-execute when their dependencies change, so you must declare loaderDeps returning the relevant search params. Without loaderDeps, the loader caches its result and ignores search param updates.

How do I code split routes in TanStack Router?▼

With file-based routing, split a route into a main file containing the loader and a .lazy.tsx file containing the component, pending, and error components. For code-based routes, call .lazy() on the route with a dynamic import.