Skip to main content

reactRouter

The reactRouter Vite plugin enables Framework Mode with type-safe routing, automatic code splitting, and server-side rendering.

Import

Usage

Configuration

The reactRouter plugin does not accept direct options. Instead, configuration is managed through:
  1. react-router.config.ts - Application-level configuration
  2. routes.ts - Route structure and organization
  3. Vite config - Build and dev server settings

Configuration Files

See react-router.config.ts for application configuration options including:
  • App directory location
  • Build output settings
  • SSR and prerendering
  • Server bundles
  • Future flags
See routes.ts for route configuration including:
  • Route definitions with route(), index(), layout()
  • File-system routing with flatRoutes()
  • Nested route hierarchies
  • Custom route IDs
Standard Vite configuration applies:

Features

The reactRouter plugin provides:

Automatic Type Generation

Generates TypeScript types for your routes in .react-router/types/:

Code Splitting

Automatically splits routes into separate chunks for optimal loading:
  • Each route module is a separate chunk
  • Shared dependencies are extracted
  • Critical CSS is inlined

Dev Server

Provides a development server with:
  • Hot Module Replacement (HMR)
  • Fast refresh for route modules
  • Server-side rendering in development
  • Automatic route discovery

Production Build

Optimizes your application for production:
  • Client and server bundles
  • Asset manifest generation
  • CSS extraction and optimization
  • Tree shaking of unused exports

Common Patterns

Basic Setup

Multiple Server Bundles

Configure server bundles in react-router.config.ts:

Custom Base Path

Prerendering Static Pages

Environment Variables

Vite’s environment variable system works automatically:
Only variables prefixed with VITE_ are exposed to client code.

TypeScript

The plugin automatically generates types. Ensure your tsconfig.json includes:

Plugin Order

The reactRouter plugin should be placed first in most cases:
Some plugins like cloudflareDevProxy must come before reactRouter.