Vite Plugin
Vite plugin for TanStack Router with automatic route generation, code splitting, and development features.Installation
Basic Usage
Configuration Options
Directory containing route files.Default:
'./src/routes'Output path for generated route tree file.Default:
'./src/routeTree.gen.ts'Prefix to ignore when generating routes.Default: Files starting with this prefix (e.g.,
'-'_component.tsx) will be ignored.Pattern to ignore when generating routes.
Quote style for generated code.Default:
'single'Whether to use semicolons in generated code.Default:
falseEnable automatic code splitting.Default:
falseAdvanced code splitting configuration.
Enable/disable route generation.Default:
trueCode Splitting Options
Configure how routes are split into separate chunks.Default splitting strategy for all routes.Default:
[['component'], ['pendingComponent'], ['errorComponent'], ['notFoundComponent']]Custom splitting strategy per route.
Route properties to remove during splitting.
Add Hot Module Replacement support.Default:
trueExamples
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 arouteTree.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:routesDirectorypath 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.jsoninclude - Router is properly registered in your app