Skip to main content

Vite Plugin

Vite plugin for TanStack Router with automatic route generation, code splitting, and development features.

Installation

Basic Usage

Configuration Options

string
Directory containing route files.Default: './src/routes'
string
Output path for generated route tree file.Default: './src/routeTree.gen.ts'
string
Prefix to ignore when generating routes.Default: '-'
Files starting with this prefix (e.g., _component.tsx) will be ignored.
RegExp
Pattern to ignore when generating routes.
'single' | 'double'
Quote style for generated code.Default: 'single'
boolean
Whether to use semicolons in generated code.Default: false
boolean
Enable automatic code splitting.Default: false
CodeSplittingOptions
Advanced code splitting configuration.
boolean
Enable/disable route generation.Default: true

Code Splitting Options

Configure how routes are split into separate chunks.
Array<Array<string>>
Default splitting strategy for all routes.Default: [['component'], ['pendingComponent'], ['errorComponent'], ['notFoundComponent']]
(params: { routeId: string }) => Array<Array<string>> | undefined
Custom splitting strategy per route.
Array<string>
Route properties to remove during splitting.
boolean
Add Hot Module Replacement support.Default: true

Examples

Basic Setup

Custom Routes Directory

With Code Splitting

Custom File Patterns

Per-Route Code Splitting

Monorepo Setup

With Multiple Environments

Generated Files

The plugin generates a routeTree.gen.ts file:

File-Based Routing Conventions

TypeScript Support

The plugin automatically generates TypeScript types:

Hot Module Replacement

The plugin supports HMR for route updates:
  • Add/remove route files → route tree updates automatically
  • Edit route components → hot reload without full page refresh
  • Update route config → route tree regenerates

Troubleshooting

Routes Not Generating

Check that:
  • routesDirectory path is correct
  • Route files have proper extensions (.tsx, .ts)
  • Files don’t start with ignore prefix

Type Errors

Ensure:
  • Generated route tree file is in your tsconfig.json include
  • Router is properly registered in your app