
router-plugin
TanStack Router bundler plugin for route generation and automatic code splitting. Supports Vite, Webpack, Rspack, and esbuild. Configures autoCodeSplitting, routesDirectory, target framework, and code split groupings.
- Installs
- 344
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/tanstack/router --skill router-plugin- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads router-plugin automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Router Plugin (@tanstack/router-plugin)
Bundler plugin that powers TanStack Router's file-based routing and automatic code splitting. Works with Vite, Webpack, Rspack, and esbuild via unplugin.
CRITICAL: The router plugin MUST come before the framework plugin (React, Solid, Vue) in the Vite config. Wrong order causes route generation and code splitting to fail silently.
Install
npm install -D @tanstack/router-plugin
Bundler Setup
Vite (most common)
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { tanstackRouter } from '@tanstack/router-plugin/vite'
export default defineConfig({
plugins: [
// MUST come before react()
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
}),
react(),
],
})
Webpack
// webpack.config.js
const { tanstackRouter } = require('@tanstack/router-plugin/webpack')
module.exports = {
plugins: [
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
}),
],
}
Rspack
// rspack.config.js
const { tanstackRouter } = require('@tanstack/router-plugin/rspack')
module.exports = {
plugins: [
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
}),
],
}
esbuild
import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
import esbuild from 'esbuild'
esbuild.build({
plugins: [
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
}),
],
})
Configuration Options
Core Options
| Option | Type | Default | Description |
|---|---|---|---|
target | 'react' | 'solid' | 'vue' | 'react' | Target framework |
routesDirectory | string | './src/routes' | Directory containing route files |
generatedRouteTree | string | './src/routeTree.gen.ts' | Path for generated route tree |
autoCodeSplitting | boolean | undefined | Enable automatic code splitting |
File Convention Options
| Option | Type | Default | Description |
|---|---|---|---|
routeFilePrefix | string | undefined | Prefix filter for route files |
routeFileIgnorePrefix | string | '-' | Prefix to exclude files from routing |
routeFileIgnorePattern | string | undefined | Pattern to exclude from routing |
indexToken | string | RegExp | { regex: string; flags?: string } | 'index' | Token identifying index routes |
routeToken | string | RegExp | { regex: string; flags?: string } | 'route' | Token identifying route config files |
Code Splitting Options
tanstackRouter({
target: 'react',
autoCodeSplitting: true,
codeSplittingOptions: {
// Default groupings for all routes
defaultBehavior: [['component'], ['errorComponent'], ['notFoundComponent']],
// Per-route custom splitting
splitBehavior: ({ routeId }) => {
if (routeId === '/dashboard') {
// Keep loader and component together for dashboard
return [['loader', 'component'], ['errorComponent']]
}
// Return undefined to use defaultBehavior
},
},
})
Output Options
| Option | Type | Default | Description |
|---|---|---|---|
quoteStyle | 'single' | 'double' | 'single' | Quote style in generated code |
semicolons | boolean | false | Use semicolons in generated code |
disableTypes | boolean | false | Disable TypeScript types |
disableLogging | boolean | false | Suppress plugin logs |
addExtensions | boolean | string | false | Add file extensions to imports |
enableRouteTreeFormatting | boolean | true | Format generated route tree |
Virtual Route Config
import { routes } from './routes'
tanstackRouter({
target: 'react',
virtualRouteConfig: routes, // or './routes.ts'
})
How It Works
The composed plugin assembles up to 3 sub-plugins:
- Route Generator (always) — Watches route files and generates
routeTree.gen.ts - Code Splitter (when
autoCodeSplitting: true) — Splits route files into lazy-loaded chunks using virtual modules - HMR (dev mode, when code splitter is off) — Hot-reloads route changes without full refresh
Route Refactor Workflow
When moving, renaming, adding, or deleting file routes:
- Change the source files under
routesDirectory. Keep the exported route identifier namedRoute. - Let the bundler plugin regenerate the tree, or run
pnpm exec tsr generatewhen the project uses the CLI. - Inspect the generated diff for the expected route IDs, parents, paths, and imports. Never repair
routeTree.gen.tsby hand. - Update links, redirects,
fromnarrowing, params, preload calls, and tests that reference the old route. - Run route-generation tests, type tests, and a production build. A passing editor typecheck does not prove the plugin generated or split the new route correctly.
Commit routeTree.gen.ts; it is generated source used by the application at runtime.
Individual Plugin Exports
For advanced use, each sub-plugin is exported separately from the Vite entry:
import {
tanstackRouter, // Composed (default)
tanstackRouterGenerator, // Generator only
tanStackRouterCodeSplitter, // Code splitter only
} from '@tanstack/router-plugin/vite'
Common Mistakes
1. CRITICAL: Wrong plugin order in Vite config
The router plugin must come before the framework plugin. Otherwise, route generation and code splitting fail silently.
// WRONG — react() before tanstackRouter()
plugins: [react(), tanstackRouter({ target: 'react' })]
// CORRECT — tanstackRouter() first
plugins: [tanstackRouter({ target: 'react' }), react()]
2. HIGH: Missing target option for non-React frameworks
The target defaults to 'react'. For Solid or Vue, you must set it explicitly.
// WRONG for Solid — generates React imports
tanstackRouter({ autoCodeSplitting: true })
// CORRECT for Solid
tanstackRouter({ target: 'solid', autoCodeSplitting: true })
3. MEDIUM: Confusing autoCodeSplitting with manual lazy routes
When autoCodeSplitting is enabled, the plugin handles splitting automatically. You do NOT need manual createLazyRoute or lazyRouteComponent calls — the plugin transforms your route files at build time.
// WRONG — manual lazy loading with autoCodeSplitting enabled
const LazyAbout = lazyRouteComponent(() => import('./about'))
// CORRECT — just write normal route files, plugin handles splitting
// src/routes/about.tsx
export const Route = createFileRoute('/about')({
component: AboutPage,
})
function AboutPage() {
return <h1>About</h1>
}
4. HIGH: Editing the generated route tree
Changes to routeTree.gen.ts are overwritten and can leave source routes, generated types, and runtime routing out of sync. Fix route filenames or plugin configuration, regenerate, and verify the generated diff instead.
Cross-References
@tanstack/router-core#router-core/code-splitting— manual code splitting concepts@tanstack/virtual-file-routes#virtual-file-routes— programmatic route trees
FAQ
What does the router-plugin skill do?
TanStack Router bundler plugin for route generation and automatic code splitting. Supports Vite, Webpack, Rspack, and esbuild. Configures autoCodeSplitting, routesDirectory, target framework, and code split groupings.
How do I install router-plugin?
Run npx skills add https://github.com/tanstack/router --skill router-plugin in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/router-plugin/ (personal) or .claude/skills/router-plugin/ (project).
Which AI agents can use router-plugin?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is router-plugin safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains router-plugin?
It is published by tanstack in tanstack/router. It has 344 recorded installs.
More from tanstack/router
router-core
tanstack/router
Framework-agnostic core concepts for TanStack Router: route trees, createRouter, createRoute, createRootRoute, createRootRouteWithContext, addChildren, Register type declaration, route matching, route sorting, file naming conventions. Entry point for all router skills.
react-router
tanstack/router
React bindings for TanStack Router: RouterProvider, useRouter, useRouterState, useMatch, useMatches, useLocation, useSearch, useParams, useNavigate, useLoaderData, useLoaderDeps, useRouteContext, useBlocker, useCanGoBack, Link, Navigate, Outlet, CatchBoundary, ErrorComponent. React-specific patterns for hooks, providers, SSR hydration, and createLink with forwardRef.
react-start
tanstack/router
React bindings for TanStack Start: createStart, StartClient, StartServer, React-specific imports, re-exports from @tanstack/react-router, full project setup with React, useServerFn hook.
start-server-core
tanstack/router
Open the skill to read its SKILL.md instructions.
Popular other skills
hyperframes-cli
heygen-com/hyperframes
The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.
triage
mattpocock/skills
Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.
ask-matt
mattpocock/skills
Ask which skill or flow fits your situation. A router over the skills in this repo.
to-questionnaire
mattpocock/skills
Turn a decision you can't fully answer into a questionnaire for someone else to fill in.
loop-me
mattpocock/skills
Grill me about specs for the workflows I want to build, within this workspace.