Skip to main content

routes.ts

Defines the route structure for your React Router application in Framework Mode. Located at app/routes.ts.

Import

RouteConfig Type

Route Helpers

route()

Defines a route with a path and component.
string | null | undefined
required
URL path pattern. Use null or undefined for pathless layout routes.
  • Static: "/about"
  • Dynamic: "/users/:userId"
  • Splat: "/files/*"
string
required
Path to route module file, relative to app/ directory.
RouteConfigEntry[]
Nested child routes.
object
Additional route options:
  • id?: string - Custom route identifier
  • caseSensitive?: boolean - Case-sensitive path matching
Examples:

index()

Defines an index route (renders at parent’s path).
string
required
Path to route module file.
{ id?: string }
Optional custom route ID.
Examples:

layout()

Defines a layout route that wraps children without adding to the URL.
string
required
Path to layout component file.
RouteConfigEntry[]
Routes to wrap with this layout.
{ id?: string }
Optional custom route ID.
Examples:

prefix()

Adds a path prefix to multiple routes without a layout component.
string
required
Path segment to prepend to all routes.
RouteConfigEntry[]
required
Routes to prefix.
Examples:

File-System Routes

flatRoutes()

Generates routes from file-system structure using conventions.
File Conventions: Directory Structure Example:

Custom Base Directory

Common Patterns

Mixed Approach

Combine file-system routes with manual configuration:

Nested Route Groups

Dynamic Route Segments

Relative Route Helpers

Organize routes across multiple files:

Resource Routes (No UI)

Validation

The route config is validated at build time:

TypeScript

Ensure proper type checking: