Skip to main content
Deploy React Router applications to Cloudflare Workers with automatic SSR detection and configuration.

Installation

Install the required dependencies:

Configuration

Configuration Options

Properties

  • main: Path to workers entry point
    • Default: workers/app.ts
  • bindings: Cloudflare bindings (KV, R2, D1, etc.)
  • build: Build command override
    • Default: react-router typegen && react-router build
  • dev: Dev command override
    • Default: react-router typegen && react-router dev
  • entrypoint: Worker entrypoint path
    • Default: build/server/index.js (SSR mode)
  • assets: Static assets directory
    • Default: build/client
  • spa: Single-page application mode
    • Auto-detected from react-router.config.ts

SSR vs SPA Mode

The resource automatically detects whether SSR is enabled by checking react-router.config.ts:

Server-Side Rendering (Default)

React Router enables SSR by default:

Client-Side Only

Disable SSR for client-side routing:

Accessing Bindings

Access Cloudflare bindings in your React Router loaders and actions:

Loaders

Actions

TypeScript Configuration

Generate type-safe bindings with React Router’s type generation:
This creates types in .react-router/types/ based on your workers/app.ts.

Local Development

The React Router dev server provides:
  • Hot module replacement
  • Type generation
  • Cloudflare Workers emulation
Start the dev server:

Build Configuration

Customize the build process:

Node.js Compatibility

React Router automatically sets compatibility: "node" for Node.js API support:
  • Node.js built-in modules
  • npm packages with Node.js dependencies
  • Full React Router feature set

Deployment Best Practices

  • Keep build/ directory in .gitignore
  • Generate types before deploying
  • Use environment variables for secrets
  • Configure bindings in alchemy.run.ts
  • Test locally with React Router dev server