Skip to main content

react-router.config.ts

Configures React Router application settings. Located at react-router.config.ts in your project root.

Import

ReactRouterConfig Type

Configuration Options

appDirectory

string
default:"app"
Path to the application directory, relative to project root.

basename

string
default:"/"
Base path for all routes. Useful when your app is served from a subdirectory.
Must match Vite’s base config:

buildDirectory

string
default:"build"
Path to the build output directory, relative to project root.
Output structure:

buildEnd

function
Hook called after build completes. Useful for custom post-build tasks.
Example:

future

object
Enables future features and breaking changes.
Example:
Flags:
  • unstable_optimizeDeps - Optimize dependency pre-bundling
  • unstable_subResourceIntegrity - Generate SRI hashes for scripts
  • unstable_trailingSlashAwareDataRequests - Handle trailing slashes in data requests
  • unstable_previewServerPrerendering - Prerender with Vite preview server
  • v8_middleware - Enable route middleware
  • v8_splitRouteModules - Automatic route code splitting (true | "enforce")
  • v8_viteEnvironmentApi - Use Vite Environment API

prerender

boolean | string[] | function | object
Defines which routes to prerender at build time as static HTML.Types:
Examples:

presets

Preset[]
Configuration presets for platform integrations.
Example:

routeDiscovery

object
Controls lazy route discovery behavior.
Default: { mode: "lazy", manifestPath: "/__manifest" } (when SSR enabled)Examples:
Lazy mode requires SSR. With ssr: false, mode is automatically "initial".

serverBuildFile

string
default:"index.js"
Filename for the server build output.
Output: build/server/server.js

serverBundles

function
Split server code into multiple bundles based on route.
Example:
Outputs:

serverModuleFormat

'esm' | 'cjs'
default:"esm"
Module format for server build output.
Most modern runtimes support ESM. Use CJS only if required by your deployment platform.

ssr

boolean
default:"true"
Enables server-side rendering. Set to false for SPA mode.
SPA Mode:
  • Pre-renders / at build time
  • Saves as index.html
  • No server required
  • All routes client-side only

allowedActionOrigins

string[]
Whitelist of allowed origins for form submissions. Supports glob patterns.
Does not apply to resource routes (routes without UI components).
Runtime Override:

Complete Example

Common Patterns

Multi-Region Deployment

Development vs Production

Incremental Static Regeneration Pattern

Custom Build Artifacts

TypeScript

Ensure proper type checking:

Validation

Config is validated at build time: