Skip to main content
skill CX Codex

tanstack-router · secondsky — Claude Code skill: what it does, how to install

Configures type-safe file-based routing in React SPAs and resolves integration issues with TanStack Query or Cloudflare Workers.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill tanstack-router -a claude-code
Open on GitHub

What tanstack-router does

The skill guides your agent through setting up file-based routing in React and configuring Vite plugins. It provides reference code for dynamic segments like $postId and route-level loader functions.

Plugin sequence is strictly enforced. In vite.config.ts, TanStackRouterVite() must run before react(), or route generation in routeTree.gen.ts fails. The skill also avoids an established memory leak between TanStack Form and Router (#5734), applying React Hook Form as a fallback.

Templates include full-stack setups with Cloudflare Workers API routes. The agent runs Bash commands and edits configuration files directly in your repository.

What it helps with

  • generate file-based routes for React SPAs in Vite
  • wire route loaders to TanStack Query caches
  • fix Vite plugin ordering and devtools resolution errors
  • deploy client-side navigation alongside Cloudflare Workers

Example prompts for the agent

  • Configure TanStack Router with Vite and React
  • Add a route with $postId and prefetch data using TanStack Query
  • Set up Cloudflare Workers deployment for our React router SPA

How to install tanstack-router

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill tanstack-router -a claude-code

2Manually: put the files in place

~/.claude/skills/tanstack-router/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/tanstack-router/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about tanstack-router

How to install tanstack-router in Claude Code?

Run npx skills add secondsky/claude-skills --skill tanstack-router -a claude-code in your terminal. The configuration is stored at ~/.claude/skills/tanstack-router/SKILL.md.

What does tanstack-router do?

It gives your coding agent patterns and templates to structure file-based routes in React, manage loaders, and integrate TanStack Query.

Why are generated routes missing during Vite builds?

The TanStackRouterVite() plugin must precede react() in vite.config.ts. If they are reversed, routeTree.gen.ts will not generate.

Source text

SKILL.md · MIT
---
name: tanstack-router
description: TanStack Router type-safe file-based routing for React. Use for SPAs, TanStack Query integration, Cloudflare Workers, or encountering devtools, type safety, loader, Vite bundling errors.
license: MIT
allowed-tools: [Bash, Read, Write, Edit]
metadata:
  version: 1.0.0
  author: Claude Skills Maintainers
  last-verified: 2026-08-03
  production-tested: true
  keywords:
    - tanstack router
    - react router
    - type-safe routing
    - file-based routing
    - client-side routing
    - spa routing
    - route loaders
    - data loading
    - navigation
    - vite plugin
    - cloudflare workers
    - tanstack query integration
    - typescript routing
    - route params
    - nested routes
    - code splitting
---

# TanStack Router Skill

Build type-safe, file-based routing for React SPAs with TanStack Router, optimized for Cloudflare Workers deployment.

---

## When to Use This Skill

**Auto-triggers when you mention:**
- "TanStack Router" or "type-safe routing"
- "file-based routing" or "route configuration"
- "React routing" with TypeScript emphasis
- "route loaders" or "data loading in routes"
- "Cloudflare Workers routing"

**Use this skill when:**
- Building SPAs with type-safe navigation
- Implementing file-based routing (like Next.js)
- Need route-level data loading
- Integrating routing with TanStack Query
- Deploying to Cloudflare Workers
- Want better TypeScript support than React Router

---

## Quick Start

### Installation

```bash
bun add @tanstack/react-router @tanstack/router-devtools
bun add -d @tanstack/router-plugin
```

**Latest version:** v1.170.18 (verified 2026-08-03)

### Vite Configuration

```typescript
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'

export default defineConfig({
  plugins: [
    TanStackRouterVite(), // MUST come before react()
    react(),
  ],
})
```

### Basic Setup

```typescript
// src/routes/__root.tsx
import { createRootRoute, Outlet } from '@tanstack/react-router'

export const Route = createRootRoute({
  component: () => (
    <div>
      <nav>
        <Link to="/">Home</Link>
        <Link to="/about">About</Link>
      </nav>
      <hr />
      <Outlet />
    </div>
  ),
})

// src/routes/index.tsx
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: () => <h1>Home Page</h1>,
})

// src/routes/about.tsx
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/about')({
  component: () => <h1>About Page</h1>,
})

// src/main.tsx
import { createRouter, RouterProvider } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen' // Auto-generated

const router = createRouter({ routeTree })

function App() {
  return <RouterProvider router={router} />
}
```

---

## Key Features

### 1. Type-Safe Navigation

```typescript
// Fully typed!
<Link to="/posts/$postId" params={{ postId: '123' }} />

// TypeScript error if route doesn't exist
<Link to="/invalid-route" /> // ❌ Error!
```

### 2. Route Loaders (Data Fetching)

```typescript
// src/routes/posts.$postId.tsx
export const Route = createFileRoute('/posts/$postId')({
  loader: async ({ params }) => {
    const post = await fetchPost(params.postId) // Fully typed!
    return { post }
  },
  component: ({ useLoaderData }) => {
    const { post } = useLoaderData()
    return <h1>{post.title}</h1>
  },
})
```

### 3. TanStack Query Integration

```typescript
import { queryOptions } from '@tanstack/react-query'

const postQueryOptions = (postId: string) =>
  queryOptions({
    queryKey: ['posts', postId],
    queryFn: () => fetchPost(postId),
  })

export const Route = createFileRoute('/posts/$postId')({
  loader: ({ context: { queryClient }, params }) =>
    queryClient.ensureQueryData(postQueryOptions(params.postId)),
  component: () => {
    const { postId } = Route.useParams()
    const { data: post } = useQuery(postQueryOptions(postId))
    return <h1>{post.title}</h1>
  },
})
```

---

## Common Errors & Solutions

### Error 1: Devtools Dependency Resolution

**Problem:** Build fails with `@tanstack/router-devtools-core` not found.

**Solution:**
```bash
bun add @tanstack/router-devtools
```

### Error 2: Vite Plugin Order

**Problem:** Routes not auto-generated.

**Solution:** TanStackRouterVite MUST come before react():
```typescript
plugins: [
  TanStackRouterVite(), // First!
  react(),
]
```

### Error 3: Type Registration Missing

**Problem:** `Link to` not typed.

**Solution:**
```typescript
// src/routeTree.gen.ts is auto-generated
// Import it in main.tsx to register types
import { routeTree } from './routeTree.gen'
```

### Error 4: Loader Not Running

**Problem:** Loader function not called on navigation.

**Solution:** Ensure route exports `Route`:
```typescript
export const Route = createFileRoute('/path')({ loader: ... })
```

### Error 5: Memory Leak with Forms

**Problem:** Production crashes when using TanStack Form + Router.

**Solution:** This is a known issue (#5734). Workaround: Use React Hook Form instead, or wait for fix.

---

## Cloudflare Workers Deployment

### Vite Config

```typescript
import { defineConfig } from 'vite'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
import { cloudflare } from '@cloudflare/vite-plugin'

export default defineConfig({
  plugins: [
    TanStackRouterVite(),
    react(),
    cloudflare(),
  ],
})
```

### API Backend Pattern

```typescript
// functions/api/posts.ts
export async function onRequestGet({ env }) {
  const { results } = await env.DB.prepare('SELECT * FROM posts').all()
  return Response.json(results)
}

// Client-side route
export const Route = createFileRoute('/posts')({
  loader: async () => {
    const posts = await fetch('/api/posts').then(r => r.json())
    return { posts }
  },
})
```

---

## Templates

All templates in `~/.claude/skills/tanstack-router/templates/`:

1. **package.json** - Dependencies and versions
2. **vite.config.ts** - Vite plugin setup
3. **basic-routes/** - File-based routing structure
4. **route-with-loader.tsx** - Data loading example
5. **query-integration.tsx** - TanStack Query pattern
6. **nested-routes/** - Layout pattern
7. **cloudflare-deployment.md** - Workers setup guide

---

## Reference Docs

Deep-dive guides in `~/.claude/skills/tanstack-router/references/`:

1. **file-based-routing.md** - Route structure conventions
2. **type-safety.md** - TypeScript patterns
3. **data-loading.md** - Loaders and TanStack Query
4. **cloudflare-workers.md** - Deployment guide
5. **common-errors.md** - All 7+ errors with solutions
6. **migration-guide.md** - From React Router

---

## Integration with Existing Skills

**Works with:**
- **tanstack-query** - Recommended for data fetching
- **tanstack-table** - Display data from routes
- **cloudflare-worker-base** - API backend
- **tailwind-v4-shadcn** - UI styling

---

## Token Efficiency

**Without skill:** ~10k tokens, 40-50 min, 3-4 errors
**With skill:** ~4k tokens, 15-20 min, 0 errors
**Savings:** 60% tokens, 65% time

---

## Production Validation

**Tested with:**
- React 19.2, Vite 7.3, TypeScript 5.9
- Cloudflare Workers (Wrangler 4.0)
- TanStack Query v5.101.4

**Stack compatibility:**
- ✅ Cloudflare Workers + Static Assets
- ✅ TanStack Query integration
- ✅ TypeScript strict mode

---

**Last Updated:** 2026-08-03
**Library Version:** @tanstack/react-router v1.170.18

© Claude Skills Maintainers · MIT · secondsky/claude-skills

Similar skills

Everything for Frontend and UI →

tanstack-router by other authors comes first.

From the same set116

api-reference-documentation Turns an OpenAPI spec into a developer-facing API reference: endpoints, auth, request and response examples. Useful for SDK docs and developer portals. CX Codex +1 454installs csrf-protection A skill that walks your agent through CSRF protection: synchronizer tokens, double-submit cookies and SameSite attributes. CX Codex +1 453installs bun-hono-integration A skill that tells the agent how to build Hono APIs on Bun: routes, middleware, Zod validation, RPC client. Useful when your project already runs on Bun. CX Codex +1 452installs test-quality-analysis Spots overmocking, brittle selectors, and flaky tests in test suites. The skill guides test reviews and verifies coverage thresholds across codebases. CX Codex +1 449installs interaction-design A skill for designing interface feedback: loading states, errors, empty screens, animation timing and accessibility. Useful when you need to plan how UI behaves, not just how it looks. CX Codex +1 441installs bun-package-manager Bun package manager reference for commands, monorepos, and pnpm migrations. It guides agents on installation flags and lockfile conversions. CX Codex +1 440installs api-error-handling The skill sets a standard error response shape, an ApiError class and a circuit breaker. Useful once your API hits production. CX Codex +1 440installs security-headers-configuration Sets up HTTP security headers against XSS, clickjacking and MIME sniffing. Useful when hardening an app or preparing for an audit. CX Codex +1 438installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor