plugins/react-expert/skills/react-tanstack-router/SKILL.md
TanStack Router - 100% type-safe routing, file-based routes, loaders, search params. Use when implementing routing in React apps (NOT Next.js).
npx skillsauth add fusengine/agents react-tanstack-routerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
100% type-safe router for React with file-based routing, loaders, search params validation, and deep TanStack Query integration.
Before ANY implementation, use TeamCreate to spawn 3 agents:
After implementation, run fuse-ai-pilot:sniper for validation.
TanStack Router is the recommended choice for React SPAs requiring type-safe routing with search params validation.
| Feature | TanStack Router | React Router v7 | |---------|----------------|-----------------| | Type Safety | Full inference | Auto-generated | | File-based Routing | Built-in | Framework mode | | Search Params Validation | Zod, Valibot | Manual | | Preloading | Intent, render | Limited | | TanStack Query Integration | Native | Manual |
zodValidator → search-params.mddeclare module '@tanstack/react-router' → typescript.mdRecommended structure following SOLID principles from solid-react skill.
src/
├── modules/
│ ├── cores/ # Shared between features
│ │ ├── lib/
│ │ │ ├── router/router.ts # Router configuration
│ │ │ └── query/client.ts # QueryClient configuration
│ │ ├── components/layouts/ # Shared layouts
│ │ └── interfaces/ # Shared types
│ └── [feature]/ # Feature module
│ ├── src/
│ │ ├── interfaces/ # Module types
│ │ ├── queries/ # TanStack Query options
│ │ └── components/ # Module components
│ └── index.ts # Public exports
├── routes/ # Route definitions ONLY
│ ├── __root.tsx
│ └── [feature]/
└── routeTree.gen.ts # Auto-generated (DO NOT MODIFY)
Full template: templates/basic-setup.md
| Topic | Reference | When to consult |
|-------|-----------|-----------------|
| Setup | installation.md | Vite/Webpack config, React Router migration |
| File Routing | file-based-routing.md | Naming conventions, routes/ structure |
| URL Params | route-params.md | Dynamic routes $postId, parsing |
| Search Params | search-params.md | Zod validation, URL filters, pagination |
| Data Loading | loaders.md | Loaders, prefetch, TanStack Query integration |
| Navigation | navigation.md | Link, useNavigate, redirects |
| Context | route-context.md | Dependency injection, QueryClient, user |
| Layouts | nested-routes.md | Nested layouts, Outlet, pathless routes |
| Errors | error-handling.md | Error boundaries, 404, pending states |
| Lazy Loading | code-splitting.md | Code splitting, bundle optimization |
| Preloading | preloading.md | Preload intent/render, prefetch |
| Auth | auth-guards.md | Protected routes, RBAC, login redirect |
| TanStack Query | tanstack-query.md | queryOptions, mutations, cache |
| SSR | ssr.md | Server-side rendering, TanStack Start |
| TypeScript | typescript.md | Type registration, inference, type safety |
| DevTools | devtools.md | Router DevTools setup |
| Hooks API | hooks.md | useParams, useSearch, useNavigate, etc. |
| Components | components.md | Link, Outlet, Navigate, RouterProvider |
| Template | When to use | |----------|-------------| | basic-setup.md | Start a new project with SOLID architecture | | feature-module.md | Create a complete feature module (interfaces, queries, components) | | auth-protected-routes.md | Implement login, protected routes, RBAC | | search-filters.md | Page with URL filters, pagination, sorting | | dashboard-layout.md | Dashboard with sidebar, tabs, nested layouts |
Router context configuration for dependency injection.
// src/routes/__root.tsx
export const Route = createRootRouteWithContext<RouterContext>()({
component: RootComponent,
})
Details: route-context.md Template: templates/basic-setup.md
Recommended pattern for data loading with cache.
// src/routes/posts/$postId.tsx
export const Route = createFileRoute('/posts/$postId')({
loader: ({ context: { queryClient }, params }) =>
queryClient.ensureQueryData(postQueryOptions(params.postId)),
component: PostPage,
})
Details: loaders.md, tanstack-query.md Template: templates/feature-module.md
Type-safe filters and pagination via URL.
// src/routes/posts/index.tsx
const searchSchema = z.object({
page: z.number().min(1).default(1),
sort: z.enum(['newest', 'oldest']).default('newest'),
})
export const Route = createFileRoute('/posts/')({
validateSearch: zodValidator(searchSchema),
})
Details: search-params.md Template: templates/search-filters.md
Authentication guard with redirect.
// src/routes/_authenticated/_authenticated.tsx
export const Route = createFileRoute('/_authenticated')({
beforeLoad: ({ context, location }) => {
if (!context.user) {
throw redirect({ to: '/login', search: { redirect: location.href } })
}
},
})
Details: auth-guards.md Template: templates/auth-protected-routes.md
Nested layouts for dashboards.
// src/routes/_dashboard/_dashboard.tsx
export const Route = createFileRoute('/_dashboard')({
component: () => (
<DashboardLayout>
<Outlet />
</DashboardLayout>
),
})
Details: nested-routes.md Template: templates/dashboard-layout.md
| Pattern | Reference |
|---------|-----------|
| Use Route API (Route.useParams()) | hooks.md |
| Validate search params with Zod | search-params.md |
| Use ensureQueryData in loaders | tanstack-query.md |
| Preload on intent for links | preloading.md |
| Separate interfaces in interfaces/ | solid-react skill |
| Anti-pattern | Why | Alternative |
|--------------|-----|-------------|
| useLoaderData() without from | Not type-safe | Route.useLoaderData() |
| useEffect for fetch | Not optimal | Use loaders |
| Mutate search params | Immutability | navigate({ search: {...} }) |
| Skip error boundaries | Degraded UX | Add errorComponent |
| Interfaces in components | Coupling | interfaces/ folder |
See installation.md for complete migration guide.
| React Router | TanStack Router |
|--------------|-----------------|
| useParams() | Route.useParams() |
| useSearchParams() | Route.useSearch() |
| useLoaderData() | Route.useLoaderData() |
| loader function | loader option |
| action function | TanStack Query mutations |
development
Use when optimizing entity-based / semantic SEO 2026. Covers entity maps, Google Knowledge Graph resolution, salience scoring, passage-level ranking, about/sameAs/knowsAbout schema, Cloud Natural Language API validation.
development
Use when running SEO, GEO, schema, Core Web Vitals, sitemap, hreflang, E-E-A-T, AI Overviews, technical SEO, or structured data tasks. Covers full-site audits, single-page analysis, schema markup, content quality, AI search optimization, local SEO, sitemap/robots, internal linking, semantic clustering, and search experience.
development
Use when optimizing search experience (SXO). Covers intent matching, user personas, user stories, page-type analysis, dwell time, scroll depth, pogo-sticking prevention.
development
Use when optimizing local SEO. Covers Google Business Profile, NAP consistency, citations, reviews acquisition, Local Pack ranking, location pages, LocalBusiness schema.