neue Homepage auf react basis

This commit is contained in:
2026-08-07 21:39:30 +02:00
parent 164bdd19ad
commit ee89442c04
52191 changed files with 1230242 additions and 58 deletions
+363
View File
@@ -0,0 +1,363 @@
---
title: Framework Adoption from Component Routes
order: 4
---
# Framework Adoption from Component Routes
If you are using `<RouterProvider>` please see [Framework Adoption from RouterProvider][upgrade-router-provider] instead.
If you are using `<Routes>` this is the right place.
The React Router Vite plugin adds framework features to React Router. This guide will help you adopt the plugin in your app. If you run into any issues, please reach out for help on [Twitter](https://x.com/remix_run) or [Discord](https://remix.run/discord).
## Features
The Vite plugin adds:
- Route loaders, actions, and automatic data revalidation
- Type-safe Routes Modules
- Automatic route code-splitting
- Automatic scroll restoration across navigations
- Optional Static pre-rendering
- Optional Server rendering
The initial setup requires the most work. However, once complete, you can adopt new features incrementally, one route at a time.
## Prerequisites
To use the Vite plugin, your project requires:
- Node.js 22.22.0+
- Vite 7+ or Vite 8+
## 1. Install the Vite plugin
**👉 Install the React Router Vite plugin**
```shellscript nonumber
npm install -D @react-router/dev
```
**👉 Install a runtime adapter**
We will assume you are using Node as your runtime.
```shellscript nonumber
npm install @react-router/node
```
**👉 Swap out the React plugin for React Router.**
```tsx diff filename=vite.config.ts
-import react from '@vitejs/plugin-react'
+import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
- react()
+ reactRouter()
],
});
```
## 2. Add the React Router config
**👉 Create a `react-router.config.ts` file**
Add the following to the root of your project. In this config you can tell React Router about your project, like where to find the app directory and to not use SSR (server-side rendering) for now.
```shellscript nonumber
touch react-router.config.ts
```
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
appDirectory: "src",
ssr: false,
} satisfies Config;
```
## 3. Add the Root entry point
In a typical Vite app, the `index.html` file is the entry point for bundling. The React Router Vite plugin moves the entry point to a `root.tsx` file so you can use React to render the shell of your app instead of static HTML, and eventually upgrade to Server Rendering if you want.
**👉 Move your existing `index.html` to `root.tsx`**
For example, if your current `index.html` looks like this:
```html filename=index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>My App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
```
You would move that markup into `src/root.tsx` and delete `index.html`:
```shellscript nonumber
touch src/root.tsx
```
```tsx filename=src/root.tsx
import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "react-router";
export function Layout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>My App</title>
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function Root() {
return <Outlet />;
}
```
## 4. Add client entry module
In the typical Vite app the `index.html` file points to `src/main.tsx` as the client entry point. React Router uses a file named `src/entry.client.tsx` instead.
**👉 Make `src/entry.client.tsx` your entry point**
If your current `src/main.tsx` looks like this:
```tsx filename=src/main.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router";
import "./index.css";
import App from "./App";
ReactDOM.createRoot(
document.getElementById("root")!,
).render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
);
```
You would rename it to `entry.client.tsx` and change it to this:
```tsx filename=src/entry.client.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import { HydratedRouter } from "react-router/dom";
import "./index.css";
ReactDOM.hydrateRoot(
document,
<React.StrictMode>
<HydratedRouter />
</React.StrictMode>,
);
```
- Use `hydrateRoot` instead of `createRoot`
- Render a `<HydratedRouter>` instead of your `<App/>` component
- Note: we stopped rendering the `<App/>` component. We'll bring it back in a later step, but first we want to get the app to boot with the new entry point.
## 5. Shuffle stuff around
Between `root.tsx` and `entry.client.tsx`, you may want to shuffle some stuff around between them.
In general:
- `root.tsx` contains any rendering things like context providers, layouts, styles, etc.
- `entry.client.tsx` should be as minimal as possible
- Remember to _not_ try to render your existing `<App/>` component yet, we'll do that in a later step
Note that your `root.tsx` file will be statically generated and served as the entry point of your app, so just that module will need to be compatible with server rendering. This is where most of your trouble will come.
## 6. Set up your routes
The React Router Vite plugin uses a `routes.ts` file to configure your routes. For now we'll add a simple catchall route to get things going.
**👉 Set up a `catchall.tsx` route**
```shellscript nonumber
touch src/routes.ts src/catchall.tsx
```
```ts filename=src/routes.ts
import {
type RouteConfig,
route,
} from "@react-router/dev/routes";
export default [
// * matches all URLs, the ? makes it optional so it will match / as well
route("*?", "catchall.tsx"),
] satisfies RouteConfig;
```
**👉 Render a placeholder route**
Eventually we'll replace this with our original `App` component, but for now we'll just render something simple to make sure we can boot the app.
```tsx filename=src/catchall.tsx
export default function Component() {
return <div>Hello, world!</div>;
}
```
[View our guide on configuring routes][configuring-routes] to learn more about the `routes.ts` file.
## 7. Boot the app
At this point you should be able to boot the app and see the root layout.
**👉 Add `dev` script and run the app**
```json filename=package.json
"scripts": {
"dev": "react-router dev"
}
```
Now make sure you can boot your app at this point before moving on:
```shellscript
npm run dev
```
You will probably want to add `.react-router/` to your `.gitignore` file to avoid tracking unnecessary files in your repository.
```txt
.react-router/
```
You can check out [Type Safety][type-safety] to learn how to fully set up and use autogenerated type safety for params, loader data, and more.
## 8. Render your app
To get back to rendering your app, we'll update the "catchall" route we set up earlier that matches all URLs so that your existing `<Routes>` get a chance to render.
**👉 Update the catchall route to render your app**
```tsx filename=src/catchall.tsx
import App from "./App";
export default function Component() {
return <App />;
}
```
Your app should be back on the screen and working as usual!
## 9. Migrate a route to a Route Module
You can now incrementally migrate your routes to route modules.
Given an existing route like this:
```tsx filename=src/App.tsx
// ...
import About from "./containers/About";
export default function App() {
return (
<Routes>
<Route path="/about" element={<About />} />
</Routes>
);
}
```
**👉 Add the route definition to `routes.ts`**
```tsx filename=src/routes.ts
import {
type RouteConfig,
route,
} from "@react-router/dev/routes";
export default [
route("/about", "./pages/about.tsx"),
route("*?", "catchall.tsx"),
] satisfies RouteConfig;
```
**👉 Add the route module**
Edit the route module to use the [Route Module API][route-modules]:
```tsx filename=src/pages/about.tsx
export async function clientLoader() {
// you can now fetch data here
return {
title: "About page",
};
}
export default function Component({ loaderData }) {
return <h1>{loaderData.title}</h1>;
}
```
See [Type Safety][type-safety] to set up autogenerated type safety for params, loader data, and more.
The first few routes you migrate are the hardest because you often have to access various abstractions a bit differently than before (like in a loader instead of from a hook or context). But once the trickiest bits get dealt with, you get into an incremental groove.
## Enable SSR and/or Pre-rendering
If you want to enable server rendering and static pre-rendering, you can do so with the `ssr` and `prerender` options in the bundler plugin. For SSR you'll need to also deploy the server build to a server.
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
ssr: true,
async prerender() {
return ["/", "/about", "/contact"];
},
} satisfies Config;
```
[upgrade-router-provider]: ./router-provider
[configuring-routes]: ../start/framework/routing
[route-modules]: ../start/framework/route-module
[type-safety]: ../how-to/route-module-type-safety
+111
View File
@@ -0,0 +1,111 @@
---
title: Future Changes
order: 1
---
# Future Changes
We try our best to keep major version upgrades simple and boring through the use of opt-in APIs and [Future Flags][api-development-strategy]. Future flags are used to gate breaking changes that don't otherwise have a good call-site opt-in strategy. By adopting all opt-in APIs and future flags, you should be able to upgrade to the next major version of React Router with minimal changes.
We plan to ship new major versions roughly once a year as described in our [Open Governance Model][governance], so this guide will continue to track future changes you can adopt ahead of the next major release. v9 is currently estimated for mid-2027 when Node 22 reaches EOL.
We highly recommend you make a commit after each step and ship it instead of doing everything all at once. Most flags can be adopted in any order, with exceptions noted below.
<docs-info>This is an evolving document that will be updated throughout the duration of v8</docs-info>
## Minimum Versions
[MODES: framework, data, declarative]
<br/>
<br/>
React Router v9 will require the following minimum versions (as of now). You can prepare for the upgrade by updating them while still on v8:
- `node@24+`
## Update to latest v8.x
Before adopting any future flags or call-site opt-in changes, you should update to the latest minor version of v8.x to make sure you have access to the latest flags. You may see a number of deprecation warnings as you upgrade, which we'll cover below.
👉 Update to latest v8
```sh
npm install react-router@8 @react-router/{dev,node,etc.}@8
```
## Future Flags
_No future flags yet_
## Other Planned Breaking Changes
_No known planned breaking changes yet_
## Unstable Future Flags (Optional)
We document some [unstable] flags here as a reference for folks contributing to the project via beta testing, but they are not generally recommended for production use and may have breaking changes in patch or minor releases - adopt with caution!
### `future.unstable_enableNodeReadableStream`
[MODES: framework]
<br/>
<br/>
**Background**
Now that the Web Streams API is [stable](https://nodejs.org/docs/latest-v22.x/api/webstreams.html) in Node 22+, it's viable for React Router to use React's [`renderToReadableStream`](https://react.dev/reference/react-dom/server/renderToReadableStream) in the server entry.
When no `entry.server.tsx` file is present, React Router defaults to [`renderToPipeableStream`](https://react.dev/reference/react-dom/server/renderToPipeableStream) when a Node runtime is detected, and `renderToReadableStream` otherwise.
With this flag enabled, React Router will default to `renderToReadableStream` on all runtimes, including Node. You can continue to use `renderToPipeableStream` via a custom `entry.server.tsx` file if needed.
<docs-info>Enabling this flag might even provide slight performance gains because we are already using Web Streams internally, so this flag removes some unnecessary transforms between Web and Node streams.</docs-info>
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
unstable_enableNodeReadableStream: true,
},
} satisfies Config;
```
**Update your Code**
No code changes are required. If your app has a custom `entry.server.tsx`, this flag will not change your runtime behavior.
### `future.unstable_optimizeDeps`
[MODES: framework]
<br/>
<br/>
**Background**
This flag lets React Router provide Vite's dependency optimizer with the client entry file and route module files. This can improve dependency optimization in development, but the behavior is still experimental.
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
unstable_optimizeDeps: true,
},
} satisfies Config;
```
**Update your Code**
No code changes are required. If you run into dependency optimization issues after enabling this flag, remove the flag and restart the dev server.
[api-development-strategy]: ../community/api-development-strategy
[governance]: https://github.com/remix-run/react-router/blob/main/GOVERNANCE.md#design-goals
[unstable]: ../community/api-development-strategy#unstable-flags
+4
View File
@@ -0,0 +1,4 @@
---
title: Upgrading
order: 2
---
+445
View File
@@ -0,0 +1,445 @@
---
title: Framework Adoption from RouterProvider
order: 5
---
# Framework Adoption from RouterProvider
If you are not using `<RouterProvider>` please see [Framework Adoption from Component Routes][upgrade-component-routes] instead.
The React Router Vite plugin adds framework features to React Router. This guide will help you adopt the plugin in your app. If you run into any issues, please reach out for help on [Twitter](https://x.com/remix_run) or [Discord](https://remix.run/discord).
## Features
The Vite plugin adds:
- Route loaders, actions, and automatic data revalidation
- Type-safe Routes Modules
- Automatic route code-splitting
- Automatic scroll restoration across navigations
- Optional Static pre-rendering
- Optional Server rendering
The initial setup requires the most work. However, once complete, you can adopt new features incrementally.
## Prerequisites
To use the Vite plugin, your project requires:
- Node.js 22.22.0+
- Vite 7+ or Vite 8+
## 1. Move route definitions into route modules
The React Router Vite plugin renders its own `RouterProvider`, so you can't render an existing `RouterProvider` within it. Instead, you will need to format all of your route definitions to match the [Route Module API][route-modules].
This step will take the longest, however there are several benefits to doing this regardless of adopting the React Router Vite plugin:
- Route modules will be lazy loaded, decreasing the initial bundle size of your app
- Route definitions will be uniform, simplifying your app's architecture
- Moving to route modules is incremental, you can migrate one route at a time
**👉 Move your route definitions into route modules**
Export each piece of your route definition as a separate named export, following the [Route Module API][route-modules].
```tsx filename=src/routes/about.tsx
export async function clientLoader() {
return {
title: "About",
};
}
export default function About() {
let data = useLoaderData();
return <div>{data.title}</div>;
}
// clientAction, ErrorBoundary, etc.
```
**👉 Create a convert function**
Create a helper function to convert route module definitions into the format expected by your data router:
```tsx filename=src/main.tsx
function convert(m: any) {
let {
clientLoader,
clientAction,
default: Component,
...rest
} = m;
return {
...rest,
loader: clientLoader,
action: clientAction,
Component,
};
}
```
**👉 Lazy load and convert your route modules**
Instead of importing your route modules directly, lazy load and convert them to the format expected by your data router.
Not only does your route definition now conform to the Route Module API, but you also get the benefits of code-splitting your routes.
```tsx diff filename=src/main.tsx
let router = createBrowserRouter([
// ... other routes
{
path: "about",
- loader: aboutLoader,
- Component: About,
+ lazy: () => import("./routes/about").then(convert),
},
// ... other routes
]);
```
Repeat this process for each route in your app.
## 2. Install the Vite plugin
Once all of your route definitions are converted to route modules, you can adopt the React Router Vite plugin.
**👉 Install the React Router Vite plugin**
```shellscript nonumber
npm install -D @react-router/dev
```
**👉 Install a runtime adapter**
We will assume you are using Node as your runtime.
```shellscript nonumber
npm install @react-router/node
```
**👉 Swap out the React plugin for React Router**
```tsx diff filename=vite.config.ts
-import react from '@vitejs/plugin-react'
+import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
- react()
+ reactRouter()
],
});
```
## 3. Add the React Router config
**👉 Create a `react-router.config.ts` file**
Add the following to the root of your project. In this config you can tell React Router about your project, like where to find the app directory and to not use SSR (server-side rendering) for now.
```shellscript nonumber
touch react-router.config.ts
```
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
appDirectory: "src",
ssr: false,
} satisfies Config;
```
## 4. Add the Root entry point
In a typical Vite app, the `index.html` file is the entry point for bundling. The React Router Vite plugin moves the entry point to a `root.tsx` file so you can use React to render the shell of your app instead of static HTML, and eventually upgrade to Server Rendering if you want.
**👉 Move your existing `index.html` to `root.tsx`**
For example, if your current `index.html` looks like this:
```html filename=index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>My App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
```
You would move that markup into `src/root.tsx` and delete `index.html`:
```shellscript nonumber
touch src/root.tsx
```
```tsx filename=src/root.tsx
import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "react-router";
export function Layout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>My App</title>
<Meta />
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export default function Root() {
return <Outlet />;
}
```
**👉 Move everything above `RouterProvider` to `root.tsx`**
Any global styles, context providers, etc. should be moved into `root.tsx` so they can be shared across all routes.
For example, if your `App.tsx` looks like this:
```tsx filename=src/App.tsx
import "./index.css";
export default function App() {
return (
<OtherProviders>
<AppLayout>
<RouterProvider router={router} />
</AppLayout>
</OtherProviders>
);
}
```
You would move everything above the `RouterProvider` into `root.tsx`.
```tsx diff filename=src/root.tsx
+import "./index.css";
// ... other imports and Layout
export default function Root() {
return (
+ <OtherProviders>
+ <AppLayout>
<Outlet />
+ </AppLayout>
+ </OtherProviders>
);
}
```
## 5. Add client entry module (optional)
In the typical Vite app the `index.html` file points to `src/main.tsx` as the client entry point. React Router uses a file named `src/entry.client.tsx` instead.
If no `entry.client.tsx` exists, the React Router Vite plugin will use a default, hidden one.
**👉 Make `src/entry.client.tsx` your entry point**
If your current `src/main.tsx` looks like this:
```tsx filename=src/main.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import {
createBrowserRouter,
RouterProvider,
} from "react-router";
import App from "./App";
const router = createBrowserRouter([
// ... route definitions
]);
ReactDOM.createRoot(
document.getElementById("root")!,
).render(
<React.StrictMode>
<RouterProvider router={router} />;
</React.StrictMode>,
);
```
You would rename it to `entry.client.tsx` and change it to this:
```tsx filename=src/entry.client.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import { HydratedRouter } from "react-router/dom";
ReactDOM.hydrateRoot(
document,
<React.StrictMode>
<HydratedRouter />
</React.StrictMode>,
);
```
- Use `hydrateRoot` instead of `createRoot`
- Render a `<HydratedRouter>` instead of your `<App/>` component
- Note: We are no longer creating the routes and manually passing them to `<RouterProvider />`. We will migrate our route definitions in the next step.
## 6. Migrate your routes
The React Router Vite plugin uses a `routes.ts` file to configure your routes. The format will be pretty similar to the definitions of your data router.
**👉 Move definitions to a `routes.ts` file**
```shellscript nonumber
touch src/routes.ts src/catchall.tsx
```
Move your route definitions to `routes.ts`. Note that the schemas don't match exactly, so you will get type errors; we'll fix this next.
```tsx diff filename=src/routes.ts
+import type { RouteConfig } from "@react-router/dev/routes";
-const router = createBrowserRouter([
+export default [
{
path: "/",
lazy: () => import("./routes/layout").then(convert),
children: [
{
index: true,
lazy: () => import("./routes/home").then(convert),
},
{
path: "about",
lazy: () => import("./routes/about").then(convert),
},
{
path: "todos",
lazy: () => import("./routes/todos").then(convert),
children: [
{
path: ":id",
lazy: () =>
import("./routes/todo").then(convert),
},
],
},
],
},
-]);
+] satisfies RouteConfig;
```
**👉 Replace the `lazy` loader with a `file` loader**
```tsx diff filename=src/routes.ts
export default [
{
path: "/",
- lazy: () => import("./routes/layout").then(convert),
+ file: "./routes/layout.tsx",
children: [
{
index: true,
- lazy: () => import("./routes/home").then(convert),
+ file: "./routes/home.tsx",
},
{
path: "about",
- lazy: () => import("./routes/about").then(convert),
+ file: "./routes/about.tsx",
},
{
path: "todos",
- lazy: () => import("./routes/todos").then(convert),
+ file: "./routes/todos.tsx",
children: [
{
path: ":id",
- lazy: () => import("./routes/todo").then(convert),
+ file: "./routes/todo.tsx",
},
],
},
],
},
] satisfies RouteConfig;
```
[View our guide on configuring routes][configuring-routes] to learn more about the `routes.ts` file and helper functions to further simplify the route definitions.
## 7. Boot the app
At this point you should be fully migrated to the React Router Vite plugin. Go ahead and update your `dev` script and run the app to make sure everything is working.
**👉 Add `dev` script and run the app**
```json filename=package.json
"scripts": {
"dev": "react-router dev"
}
```
Now make sure you can boot your app at this point before moving on:
```shellscript
npm run dev
```
You will probably want to add `.react-router/` to your `.gitignore` file to avoid tracking unnecessary files in your repository.
```txt
.react-router/
```
You can checkout [Type Safety][type-safety] to learn how to fully setup and use autogenerated type safety for params, loader data, and more.
## Enable SSR and/or Pre-rendering
If you want to enable server rendering and static pre-rendering, you can do so with the `ssr` and `prerender` options in the bundler plugin. For SSR you'll need to also deploy the server build to a server.
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
ssr: true,
async prerender() {
return ["/", "/about", "/contact"];
},
} satisfies Config;
```
[upgrade-component-routes]: ./component-routes
[configuring-routes]: ../start/framework/routing
[route-modules]: ../start/framework/route-module
[type-safety]: ../how-to/route-module-type-safety
+460
View File
@@ -0,0 +1,460 @@
---
title: Updating from v7
order: 2
---
# Upgrading from v7
We try our best to keep major version upgrades simple and boring through the use of opt-in APIs and [Future Flags][api-development-strategy]. Future flags are used to gate breaking changes that don't otherwise have a good call-site opt-in strategy. By adopting all opt-in APIs and future flags while still on v7, you should be able to update to React Router v8 with minimal changes.
We highly recommend you make a commit after each step and ship it instead of doing everything all at once. Most flags can be adopted in any order, with exceptions noted below.
## Minimum Versions
[MODES: framework, data, declarative]
<br/>
<br/>
React Router v8 requires the following minimum versions. Update them before updating React Router to v8:
- `node@22.22+`
- `react@19.2.7+`/`react-dom@19.2.7+`
Framework mode also requires:
- `vite@7+` (requires `future.v8_viteEnvironmentApi`)
- also make sure any custom Vite plugins or config are compatible with Vite 7
## Update to latest v7.x
Before adopting any future flags or call-site opt-in changes, update to the latest minor version of v7.x to make sure you have access to the latest flags. You may see a number of deprecation warnings as you upgrade, which we'll cover below.
👉 Update to latest v7
```sh
npm install react-router@7 @react-router/{dev,node,etc.}@7
```
## Future Flags
### `future.v8_middleware`
[MODES: framework, data]
<br/>
<br/>
**Background**
Middleware allows you to run code before and after the [`Response`][Response] generation for the matched path. This enables common patterns like authentication, logging, error handling, and data preprocessing in a reusable way. Please see the [docs](../how-to/middleware) for more information.
👉 **Enable the Flag**
In Framework mode:
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_middleware: true,
},
} satisfies Config;
```
In Data mode:
```ts
import { createBrowserRouter } from "react-router";
const router = createBrowserRouter(routes, {
future: {
v8_middleware: true,
},
});
```
**Update your Code**
If you're using the `context` parameter in `loader` and `action` functions, you may need to update your code:
- In Framework mode, if you're using `react-router-serve`, you should not need to make any updates. Otherwise, this only applies if you have a custom server with a `getLoadContext` function. Please see the docs on the middleware [`getLoadContext` changes](../how-to/middleware#changes-to-getloadcontextapploadcontext) and the instructions to [migrate to the new API](../how-to/middleware#migration-from-apploadcontext).
- In Data mode, add the `Future` module augmentation described in the [middleware docs](../how-to/middleware#1-typescript-augment-future-for-loaderaction-context) so `context` is typed correctly.
### `future.v8_splitRouteModules`
[MODES: framework]
<br/>
<br/>
**Background**
This feature enables splitting client-side route exports (`clientLoader`, `clientAction`, `clientMiddleware`, `HydrateFallback`) into separate chunks that can be loaded independently from the route component. This allows these exports to be fetched and executed while the component code is still downloading, improving performance for client-side data loading.
This can be set to `true` for opt-in behavior, or `"enforce"` to require all routes to be splittable (which will cause build failures for routes that cannot be split due to shared code).
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_splitRouteModules: true,
},
} satisfies Config;
```
**Update your Code**
No code changes are required. This is an optimization feature that works automatically once enabled.
### `future.v8_viteEnvironmentApi`
[MODES: framework]
<br/>
<br/>
**Background**
This enables support for the experimental Vite Environment API, which provides a more flexible and powerful way to configure Vite environments. This is only available when using Vite 6+.
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_viteEnvironmentApi: true,
},
} satisfies Config;
```
**Update your Code**
Most users won't need to make any changes. However, if you have custom Vite configuration that previously relied on the `isSsrBuild` flag — such as a custom server build that sets `build.rollupOptions.input` — you'll need to move that configuration under the per-environment [Environment API][vite-environment] config instead.
For example, a custom server build should move its SSR `rollupOptions` from the top-level `build` config into `environments.ssr.build`:
```tsx diff filename=vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { defineConfig } from "vite";
-export default defineConfig(({ isSsrBuild }) => ({
- build: {
- rollupOptions: isSsrBuild
- ? {
- input: "./server/app.ts",
- }
- : undefined,
- },
+export default defineConfig({
+ environments: {
+ ssr: {
+ build: {
+ rollupOptions: {
+ input: "./server/app.ts",
+ },
+ },
+ },
+ },
plugins: [reactRouter()],
-}));
+});
```
See the [`node-custom-server` template][node-custom-server-template] for a complete example.
### `future.v8_passThroughRequests`
[MODES: framework]
<br/>
<br/>
**Background**
By default, React Router normalizes the `request.url` passed to your `loader`, `action`, and `middleware` functions by removing React Router's internal implementation details. Specifically, it removes `.data` suffixes and internal search parameters like `?index` and `?_routes`.
This flag eliminates that normalization and passes the raw HTTP `request` instance to your handlers. This provides a few benefits:
- Reduces server-side overhead by eliminating multiple `new Request()` calls on the critical path
- Allows you to distinguish document from data requests in your handlers based on the presence of a `.data` suffix (useful for [observability] purposes)
If you were previously relying on the normalization of `request.url`, you can switch to use the new sibling `url` parameter which contains a `URL` instance representing the normalized location.
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_passThroughRequests: true,
},
} satisfies Config;
```
**Update your Code**
If your code relies on inspecting the request URL, you should review it for any assumptions about the URL format:
```tsx
// ❌ Before: assuming no `.data` suffix in `request.url` pathname
export async function loader({
request,
}: Route.LoaderArgs) {
let url = new URL(request.url);
if (url.pathname === "/path") {
// This check might now behave differently because the request pathname will
// contain the `.data` suffix on data requests
}
}
// ✅ After: use `url` for normalized routing logic and `request.url`
// for raw routing logic
export async function loader({
request,
url,
}: Route.LoaderArgs) {
if (url.pathname === "/path") {
// This will always have the `.data` suffix stripped
}
// And now you can distinguish between document versus data requests
let isDataRequest = new URL(
request.url,
).pathname.endsWith(".data");
}
```
### `future.v8_trailingSlashAwareDataRequests`
[MODES: framework]
<br/>
<br/>
**Background**
React Router serves Framework mode data requests from `.data` URLs. Previously, data requests for routes with and without trailing slashes could map to the same `.data` URL because trailing slashes were not considered during URL generation. This flag preserves trailing slash semantics for data request URLs to avoid ambiguity when your app distinguishes between trailing-slash and non-trailing-slash URLs.
In v7, your HTTP and `request` pathnames are as follows for `/a/b/c` and `/a/b/c/`
| URL `/a/b/c` | **HTTP pathname** | **`request` pathname`** |
| ------------ | ----------------- | ----------------------- |
| **Document** | `/a/b/c` | `/a/b/c` ✅ |
| **Data** | `/a/b/c.data` | `/a/b/c` ✅ |
| URL `/a/b/c/` | **HTTP pathname** | **`request` pathname`** |
| ------------- | ----------------- | ----------------------- |
| **Document** | `/a/b/c/` | `/a/b/c/` ✅ |
| **Data** | `/a/b/c.data` | `/a/b/c` ⚠️ |
With this flag enabled, these pathnames are made consistent through a new `_.data` format for client-side `.data` requests:
| URL `/a/b/c` | **HTTP pathname** | **`request` pathname`** |
| ------------ | ----------------- | ----------------------- |
| **Document** | `/a/b/c` | `/a/b/c` ✅ |
| **Data** | `/a/b/c.data` | `/a/b/c` ✅ |
| URL `/a/b/c/` | **HTTP pathname** | **`request` pathname`** |
| ------------- | ------------------ | ----------------------- |
| **Document** | `/a/b/c/` | `/a/b/c/` ✅ |
| **Data** | `/a/b/c/_.data` ⬅️ | `/a/b/c/` ✅ |
This flag also aligns the root data request to match this behavior by changing it from `/_root.data` to `/_.data`.
👉 **Enable the Flag**
```ts filename=react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
future: {
v8_trailingSlashAwareDataRequests: true,
},
} satisfies Config;
```
**Update your Code**
If you have custom app, CDN, cache, or rewrite logic that matches `.data` request URLs, update it to handle the new trailing-slash-aware `/_.data` format.
## Other Breaking Changes
The changes in this section are not controlled by future flags, but you can update your code while still on v7 before moving to v8.
### `meta`/`matches` `data` Values
[MODES: framework]
<br/>
<br/>
**Background**
React Router v8 removed deprecated `data` fields in favor of `loaderData` in a few places:
- `meta` function `data` argument
- `meta` function `matches` argument (`matches[i].data`)
- `useMatches()` (`matches[i].data`)
Use `loaderData` instead on `MetaArgs`, each item in `MetaArgs.matches`, and each match returned from `useMatches()`
👉 **Update your Code**
Replace `data` with `loaderData` in your `meta` functions:
```tsx diff
export function meta({
- data,
+ loaderData,
matches,
}: Route.MetaArgs) {
return [
{
- title: data.title,
+ title: loaderData.title,
},
];
}
```
If you read data from parent matches, update those references too:
```tsx diff
export function meta({ matches }: Route.MetaArgs) {
let rootMatch = matches.find((match) => match.id === "root");
- let rootData = rootMatch?.data;
+ let rootData = rootMatch?.loaderData;
return [{ title: rootData?.siteTitle }];
}
```
Replace `data` with `loaderData` on `useMatches()` calls:
```tsx diff
export default function Component({ matches, loaderData }: ComponentProps) {
let matches = useMatches();
- const rootLoaderData = matches[0].data;
+ const rootLoaderData = matches[0].loaderData;
// ...
}
```
### `react-router-dom`
[MODES: framework, data, declarative]
<br/>
<br/>
**Background**
React Router v8 removes the `react-router-dom` re-export package. In v8, you should import DOM-specific APIs from `react-router/dom` and everything else from `react-router`.
👉 **Update your Code**
Uninstall `react-router-dom`:
```sh
npm uninstall react-router-dom
```
Replace `react-router-dom` imports with `react-router` imports:
```tsx diff
-import { Link, useLocation } from "react-router-dom";
+import { Link, useLocation } from "react-router";
```
For DOM-specific APIs, import from `react-router/dom`:
```tsx diff
-import { RouterProvider } from "react-router-dom";
+import { RouterProvider } from "react-router/dom";
```
### Cloudflare Vite Plugin
[MODES: framework]
<br/>
<br/>
**Background**
React Router v8 removes the React Router Cloudflare dev proxy. Cloudflare projects should use [`@cloudflare/vite-plugin`][cloudflare-vite-plugin] instead.
👉 **Update your Code**
Replace `cloudflareDevProxy` with `cloudflare`:
```tsx diff filename=vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
-import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";
+import { cloudflare } from "@cloudflare/vite-plugin";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
- cloudflareDevProxy(),
+ cloudflare(),
reactRouter(),
],
});
```
### `@react-router/architect` `useRequestContextDomainName`
[MODES: framework]
<br/>
<br/>
**Background**
In v7, the `@react-router/architect` adapter uses `X-Forwarded-Host` when creating the `request`, falling back to the `Host` header. In React Router v8, the adapter uses `event.requestContext.domainName` by default, falling back to the `Host` header.
👉 **Update your Code**
Opt in to the v8 behavior while still on v7 by passing `useRequestContextDomainName: true`:
```ts
import { createRequestHandler } from "@react-router/architect";
import * as build from "./build/server";
export const handler = createRequestHandler({
build,
useRequestContextDomainName: true,
});
```
This option is removed in v8 because the `event.requestContext.domainName` behavior is the default.
## Upgrade to v8
Now that your app is caught up, update to v8:
```shellscript nonumber
# data/declarative mode
npm install react-router@latest
# framework mode
npm install react-router@latest @react-router/{dev,node,etc.}@latest
```
Congratulations, you're now on v8!
[api-development-strategy]: ../community/api-development-strategy
[observability]: ../how-to/instrumentation
[Response]: https://developer.mozilla.org/en-US/docs/Web/API/Response
[vite-environment]: https://vite.dev/guide/api-environment
[node-custom-server-template]: https://github.com/remix-run/react-router-templates/blob/7c617a435510bc3add3a5395c07bc65328b65e9e/node-custom-server/vite.config.ts
[cloudflare-vite-plugin]: https://developers.cloudflare.com/workers/vite-plugin/