New advertisers: 50% off your first month with code FIRSTMONTHSee slots

Skill that adds type-safe file-based routing to React apps, with loaders and TanStack Query integration.

version
3.12.0
GitHub stars
250
View on GitHub

What it does

  • Adds the tanstack-router skill covering type-safe navigation, file-based routing, and route loaders for React
  • Covers 7 templates (Vite config, route loaders, TanStack Query integration, nested layouts, Workers deployment) and 6 reference docs
  • Documents 7 common errors, including Vite plugin ordering, missing type registration, and loaders that do not run
  • Designed for React SPAs and Cloudflare Workers projects that need routing with compile-time route validation

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.

Add marketplace

/plugin marketplace add secondsky/claude-skills

Run it inside Claude Code once, then install the plugin below.

Install

/plugin install tanstack-router@claude-skills

Run it inside Claude Code after adding the marketplace.

Files

Discovered from source

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

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

// 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

// 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

// 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)

// 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

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:

bun add @tanstack/router-devtools

Error 2: Vite Plugin Order

Problem: Routes not auto-generated.

Solution: TanStackRouterVite MUST come before react():

plugins: [
  TanStackRouterVite(), // First!
  react(),
]

Error 3: Type Registration Missing

Problem: Link to not typed.

Solution:

// 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:

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

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

// 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

Readme

TanStack Router Skill

Type-safe, file-based routing for React applications with Cloudflare Workers integration.

Auto-Trigger Keywords

  • "TanStack Router", "type-safe routing", "file-based routing"
  • "React routing TypeScript", "route loaders", "data loading routes"
  • "Cloudflare Workers routing", "SPA routing"

What This Provides

🎯 Core Features

  • Type-safe navigation - Compile-time route validation
  • File-based routing - Automatic route generation from file structure
  • Route loaders - Data fetching at route level
  • TanStack Query integration - Coordinate routing + data fetching
  • Cloudflare Workers ready - Deploy SPAs to Workers + Static Assets

📦 Templates (7)

  1. package.json - Dependencies
  2. vite.config.ts - Plugin setup
  3. basic-routes/ - File structure example
  4. route-with-loader.tsx - Data loading
  5. query-integration.tsx - TanStack Query
  6. nested-routes/ - Layouts
  7. cloudflare-deployment.md - Workers guide

📚 Reference Docs (6)

  1. File-based routing conventions
  2. TypeScript type safety patterns
  3. Data loading with loaders
  4. Cloudflare Workers deployment
  5. Common errors (7+)
  6. Migration from React Router

Quick Example

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

export const Route = createFileRoute('/posts/$postId')({
  loader: async ({ params }) => {
    const post = await fetch(`/api/posts/${params.postId}`).then(r => r.json())
    return { post }
  },
  component: function Post() {
    const { post } = Route.useLoaderData()
    return <h1>{post.title}</h1>
  },
})

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

7 Errors Prevented

  1. Devtools dependency resolution
  2. Vite plugin ordering
  3. Type registration missing
  4. Loader not running
  5. Memory leaks (known issue)
  6. Middleware undefined errors
  7. API route errors after restart

Installation

npm install @tanstack/react-router @tanstack/router-devtools
npm install -D @tanstack/router-plugin

Latest: v1.170.18


Version: 1.0.0 | Last Updated: 2026-08-03

Details

Marketplace
secondsky/claude-skills
Source
plugins/tanstack-router
Category
Frontend
Keywords
tanstack-router, tanstack, router, frontend, components
Listed since
Apr 7, 2026

More from secondsky/claude-skills

All 122

Similar to tanstack-router

More Frontend & UI Code