本页还没有译文
本页 40 段还没译成Español,下面显示的是英文原文。@react-router/{adapter}
还没翻译译自英文(reactrouter.com)本页 40 段都还没译
Server Adapters
Official Adapters
Idiomatic React Router apps can generally be deployed anywhere because React Router adapts the server's request/response to the Web Fetch API. It does this through adapters. We maintain a few adapters:
@react-router/architect@react-router/cloudflare@react-router/express
These adapters are imported into your server's entry and are not used inside your React Router app itself.
If you initialized your app with npx create-react-router@latest with something other than the built-in React Router App Server (@react-router/serve), you will note a server/index.js file that imports and uses one of these adapters.
Info
If you're using the built-in React Router App Server, you don't interact with this API
Each adapter has the same API. Some adapters also have options specific to the platform you're deploying to.
@react-router/express
Here's an example with Express:
const {
createRequestHandler,
} = require("@react-router/express");
const express = require("express");
const app = express();
// needs to handle all verbs (GET, POST, etc.)
app.all(
"*",
createRequestHandler({
// `react-router build` and `react-router dev` output files to a build directory,
// you need to pass that build to the request handler
build: require("./build"),
// Return anything you want here to be available as `context` in your
// loaders and actions. This is where you can bridge the gap between your
// server and React Router
getLoadContext(req, res) {
return {};
},
}),
);Migrating from the React Router App Server
If you started an app with the React Router App Server but find that you want to take control over the Express server and customize it, it should be fairly straightforward to migrate way from @react-router/serve.
You can refer to the Express template as a reference, but here are the main changes you will need to make:
1. Update deps
npm uninstall @react-router/serve
npm install @react-router/express compression express morgan cross-env
npm install --save-dev @types/express @types/express-serve-static-core @types/morgan2. Add a server
Create your React Router Express server in server/app.ts:
import "react-router";
import { createRequestHandler } from "@react-router/express";
import express from "express";
export const app = express();
app.use(
createRequestHandler({
build: () =>
import("virtual:react-router/server-build"),
}),
);Copy the server.js into your app. This is the boilerplate setup we recommend to allow the same server code to run both the development and production builds of your app. Two separate files are used here so that the main Express server code can be written in TypeScript (server/app.ts) and compiled into your server build by React Router, and then executed via node server.js.
3. Update vite.config.ts to compile the server
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(({ isSsrBuild }) => ({
build: {
rollupOptions: isSsrBuild
? { input: "./server/app.ts" }
: undefined,
},
plugins: [reactRouter(), tsconfigPaths()],
}));4. Update package.json scripts
Update the dev and start scripts to use your new Express server:
{
// ...
"scripts": {
"dev": "cross-env NODE_ENV=development node --conditions development server.js",
"start": "node server.js"
// ...
}
// ...
}Make sure that --conditions development is included in the dev script so that the proper version of React Router is used in development.
@react-router/architect
Here's an example with Architect:
import { createRequestHandler } from "@react-router/architect";
import * as build from "./build/server";
export const handler = createRequestHandler({
build,
});@react-router/cloudflare
Here's an example with Cloudflare:
import {
RouterContextProvider,
createContext,
createRequestHandler,
} from "react-router";
const cloudflareContext = createContext<{
env: Env;
ctx: ExecutionContext;
}>();
const requestHandler = createRequestHandler(
() => import("virtual:react-router/server-build"),
import.meta.env.MODE,
);
export default {
async fetch(request, env, ctx) {
let routerContext = new RouterContextProvider();
routerContext.set(cloudflareContext, { env, ctx });
return requestHandler(request, routerContext);
},
} satisfies ExportedHandler<Env>;@react-router/node
While not a direct "adapter" like the above, this package contains utilities for working with Node-based adapters.
Node Version Support
React Router officially supports all versions of Active LTS and the latest minor line of Maintenance LTS at any given point in time.
For example, at the time of this writing (6/17/2026):
- Node 24 is in Active LTS status, so React Router officially supports all
24.xversions - Node 22 is in Maintenance LTS status and the latest release is
22.22.3, so React Router officially supports all22.22.xversions
We make this distinction for Maintenance LTS for 2 reasons:
- When security patches are released for old maintenance lines, we want to be able to bump our minimum supported versions
- This better allows us to adopt new features shipped in Active LTS and backported to Maintenance LTS and keep our implementations aligned
Updating the minimum supported Maintenance LTS minor version may be done in a React Router minor release.
Dropping support for an EOL Node major version will always be done in a React Router major release.