|
3 | 3 | The React Router Adapter for Netlify allows you to deploy your [React Router](https://reactrouter.com) app to |
4 | 4 | [Netlify Functions](https://docs.netlify.com/functions/overview/). |
5 | 5 |
|
6 | | -To deploy a React Router 7+ site to Netlify, install this package: |
7 | | - |
8 | 6 | ## How to use |
9 | 7 |
|
| 8 | +To deploy a React Router 7+ site to Netlify, install this package: |
| 9 | + |
10 | 10 | ```sh |
11 | 11 | npm install --save-dev @netlify/vite-plugin-react-router |
12 | 12 | ``` |
13 | 13 |
|
| 14 | +It's also recommended (but not required) to use the |
| 15 | +[Netlify Vite plugin](https://www.npmjs.com/package/@netlify/vite-plugin), which provides full Netlify platform |
| 16 | +emulation directly in your local dev server: |
| 17 | + |
| 18 | +```sh |
| 19 | +npm install --save-dev @netlify/vite-plugin |
| 20 | +``` |
| 21 | + |
14 | 22 | and include the Netlify plugin in your `vite.config.ts`: |
15 | 23 |
|
16 | 24 | ```typescript |
17 | 25 | import { reactRouter } from '@react-router/dev/vite' |
18 | 26 | import { defineConfig } from 'vite' |
19 | 27 | import tsconfigPaths from 'vite-tsconfig-paths' |
20 | | -import netlifyPlugin from '@netlify/vite-plugin-react-router' // <- add this |
| 28 | +import netlifyReactRouter from '@netlify/vite-plugin-react-router' // <- add this |
| 29 | +import netlify from '@netlify/vite-plugin' // <- add this (optional) |
21 | 30 |
|
22 | 31 | export default defineConfig({ |
23 | 32 | plugins: [ |
24 | 33 | reactRouter(), |
25 | 34 | tsconfigPaths(), |
26 | | - netlifyPlugin(), // <- add this |
| 35 | + netlifyReactRouter(), // <- add this |
| 36 | + netlify(), // <- add this (optional) |
27 | 37 | ], |
28 | 38 | }) |
29 | 39 | ``` |
@@ -76,6 +86,12 @@ export default function Example() { |
76 | 86 | } |
77 | 87 | ``` |
78 | 88 |
|
| 89 | +> [!IMPORTANT] |
| 90 | +> |
| 91 | +> Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided |
| 92 | +> seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to |
| 93 | +> you). |
| 94 | +
|
79 | 95 | ### Middleware context |
80 | 96 |
|
81 | 97 | React Router introduced a stable middleware feature in 7.9.0. |
@@ -103,3 +119,9 @@ export default function Home() { |
103 | 119 | return <h1>Hello world</h1> |
104 | 120 | } |
105 | 121 | ``` |
| 122 | + |
| 123 | +> [!IMPORTANT] |
| 124 | +> |
| 125 | +> Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided |
| 126 | +> seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to |
| 127 | +> you). |
0 commit comments