Skip to main content

Routing

Reatom’s routing system provides a powerful, type-safe solution for building single-page applications with nested routes, data loading, and automatic parameter validation.

Core Concepts

Reatom routing is built on these principles:
  • Declarative Routes - Define routes with path patterns and schemas
  • Type Safety - Full TypeScript inference for route parameters
  • Data Loading - Automatic data fetching with loader functions
  • Nested Routes - Hierarchical route composition
  • Framework Agnostic - Works with React, Vue, Lit, or vanilla JS

Quick Start

Basic Routes

Route Patterns

Path Parameters

Define dynamic segments with :paramName:

Search Parameters

Define query parameters with a schema:

Search-Only Routes

Create routes that only affect query parameters:

Parameter Validation

Schema Validation

Use Standard Schema (Zod, Valibot, etc.) for validation:

Custom Validators

Use functions for custom validation:

Nested Routes

Creating Child Routes

Build hierarchical route structures:

Accessing Parent Parameters

Child routes inherit parent parameters:

Route State

Match vs Exact

Route Parameters

Data Loading

Loader Functions

Automatically fetch data when routes become active:

Loader State

Loaders are extended with withAsyncData:

Cascading Loaders

Parent loaders complete before child loaders:

Automatic Abort

Loaders are automatically aborted when:
  • Navigating to a different route
  • Route parameters change
  • Parent route becomes inactive

Component Rendering

Render Functions

Define components directly in routes:

Outlet

Render active child routes:

Exact Rendering

Only render on exact match:

Programmatic Navigation

Advanced Patterns

404 Handling

Protected Routes

Route Guards

Loading Indicators

Use search-only routes for modals:

Best Practices

1. Use Nested Routes

Organize routes hierarchically:

2. Validate Parameters

Always validate and transform route parameters:

3. Use Loaders for Data

Prefer loaders over manual fetching:

4. Handle Errors

Always handle loader errors:
Always use wrap() around promises in loaders to enable automatic abort handling.