tanstack-router

Implements type-safe TanStack Router routing in Vite React TypeScript SPAs.

1|1|Updated May 24, 2026
One-click install
npx skills add https://github.com/bm629/agent-skills --skill tanstack-router-bm629
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-router
Source: https://github.com/bm629/agent-skills/tree/main/skills/tanstack-router
Command: npx skills add https://github.com/bm629/agent-skills --skill tanstack-router-bm629

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router, @tanstack/router-plugin, @tanstack/zod-adapter, @tanstack/react-query, zod, and includes references (resource) components.

What problem does it solve? Setting up TanStack Router correctly requires wiring the bundler plugin, the Register type augmentation, validated search params, loaders, and query integration — and small mistakes (missing loaderDeps, guards in components, stale plugin names) silently break type safety or serve stale data. ## Core Features & Use Cases - Type-safe router setup: createRouter, RouterProvider, and the mandatory Register declaration merge that makes every Link, useNavigate, useParams, and useSearch compile-checked against the real route tree. - File-based and code-based routing: file-naming conventions ($param, _pathless, (group), splat, trailing-underscore un-nesting) plus the full code-based createRoute/addChildren approach when the bundler plugin is unavailable. - Search params, loaders, and Query integration: validateSearch with Zod v3/v4, loaderDeps, deferred data via raw promises and Await, and the ensureQueryData-to-useSuspenseQuery handshake with TanStack Query. - Use Case: Add an authenticated /posts/$postId route with validated tab search param, a loader that primes the TanStack Query cache, a beforeLoad redirect guard, and a memory-history test that renders the routed component. ## Quick Start Use the tanstack-router skill to set up TanStack Router in my Vite React TypeScript app with a posts route that has a validated search param and a loader wired to TanStack Query.

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 TanStack Router in a Vite React TypeScript app?

Install @tanstack/react-router and the @tanstack/router-plugin dev dependency, add tanstackRouter({ target: 'react', autoCodeSplitting: true }) before react() in vite.config.ts, then create the router with createRouter and the generated routeTree, add the Register declaration merge, and render RouterProvider.

How do I validate search params in TanStack Router?

Use the route's validateSearch option with a schema. For Zod v3 wrap the schema with zodValidator from @tanstack/zod-adapter; for Zod v4 pass the schema directly. Use .catch(default) so malformed URLs fall back instead of throwing.

TanStack Router vs React Router — which should I use?

TanStack Router provides end-to-end type safety where the route tree is the type source, plus first-class validated search params and loaders. This skill covers only TanStack Router; React Router and Remix are a different router and out of scope.

Why is my TanStack Router loader serving stale data?

A loader does not re-run when search params change unless the dependency is declared in loaderDeps. Add loaderDeps: ({ search }) => ({ page: search.page }) so the loader re-executes when those params change.

How do I test a routed component without a browser URL?

Build an in-memory router with createMemoryHistory({ initialEntries: [path] }), pass it to createRouter with your route tree, and render RouterProvider. Assert with Testing Library's findBy* queries since loaders resolve asynchronously.

Does TanStack Router work with TanStack Query?

Yes. Call queryClient.ensureQueryData(queryOptions) in the route loader via router context, then read the same queryOptions with useSuspenseQuery in the component for a cache hit. Set defaultPreloadStaleTime: 0 so Query owns freshness.