You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[React Router Framework](https://reactrouter.com/start/framework/installation) is a Node.js framework for server-side-rendered React apps. But even if react-admin is designed to build Single-Page Applications, it uses React Router under the hood and integrates seamlessly.
8
+
[React Router Framework](https://reactrouter.com/start/framework/installation)(a.k.a. Remix v3) is a Node.js framework for server-side-rendered React apps. React-admin uses React Router under the hood and integrates seamlessly with React Router Framework applications.
9
9
10
10
These instructions are targeting React Router v7 in Framework mode.
11
11
@@ -25,13 +25,13 @@ This script will ask you for more details about your project. You can use the fo
25
25
26
26
## Setting Up React-Admin In React Router
27
27
28
-
Add the `react-admin` npm package, as well as a data provider package. In this example, we'll use `ra-data-json-server` to connect to a test API provided by [JSONPlaceholder](https://jsonplaceholder.typicode.com).
28
+
Next, add the required dependencies. In addition to the `react-admin` npm package, you will need a data provider package. In this example, we'll use `ra-data-json-server` to connect to a test API provided by [JSONPlaceholder](https://jsonplaceholder.typicode.com).
29
29
30
-
**Note**: `react-admin`requires the `react-router-dom` package which is not needed anymore in standard React Router applications but is still published for backward compatibility. Check the version of React Router that has been installed by `create-react-router` and use the same version. At the time of writing this tutorial, it is `7.10.1`.
30
+
`react-admin`also depends on the `react-router-dom` package. It used to be a direct dependency of `react-router`, but it's not anymore in v7 so you'll have to add it manually. Check the version of React Router that has been installed by `create-react-router` and **use the exact same version**. At the time of writing this tutorial, it is `7.11.0`.
**Tip** Don't forget to set the `<Admin basename>` prop, so that react-admin generates links relative to the "/admin/" subpath:
70
+
**Tip**: Don't forget to set the `<Admin basename>` prop, so that react-admin generates links relative to the "/admin/" subpath:
71
71
72
-
You can now start the app in `development` mode with `npm run dev`. The admin should render at `http://localhost:5173/admin/`, and you can use the Remix routing system to add more pages.
72
+
You can now start the app in development mode with `npm run dev`. The admin should render at <http://localhost:5173/admin/>.
73
73
74
74
## Adding an API
75
75
@@ -86,9 +86,11 @@ First, create a Supabase REST API and its associated PostgreSQL database directl
86
86
-`posts` with fields: `id`, `title`, and `body`
87
87
-`comments` with fields: `id`, `name`, `body`, and `postId` (a foreign key to the `posts.id` field)
88
88
89
-
You can populate these tables via the Supabse UI if you want. Supabase exposes a REST API at `https://YOUR_INSTANCE.supabase.co/rest/v1`.
89
+
You can populate these tables via the Supabse UI if you want.
90
90
91
-
Next, create a configuration to let the Remix app connect to Supabase. As Remix supports [`dotenv`](https://dotenv.org/) by default in `development` mode, you just need to create a `.env` file:
91
+
Supabase exposes a REST API at `https://YOUR_INSTANCE.supabase.co/rest/v1`.
92
+
93
+
Next, create a configuration to let the React-Router app connect to Supabase. As React Router supports [`dotenv`](https://dotenv.org/) by default in `development` mode, you just need to create a `.env` file:
92
94
93
95
```sh
94
96
# In `.env`
@@ -113,7 +115,7 @@ export default [
113
115
Then create the `app/routes/admin.api.tsx` file. Inside this file, a `loader` function should convert the GET requests into Supabase API calls, and an `action` function should do the same for POST, PUT, and DELETE requests.
@@ -217,22 +210,25 @@ export default function App() {
217
210
}
218
211
```
219
212
220
-
That's it! Now Remix both renders the admin app and serves as a proxy to the Supabase API. You can test the app by visiting `http://localhost:5173/admin/`, and the API Proxy by visiting `http://localhost:5173/admin/api/posts`.
213
+
That's it! Now React Router both renders the admin app and serves as a proxy to the Supabase API. You can test the app by visiting `http://localhost:5173/admin/`, and the API Proxy by visiting `http://localhost:5173/admin/api/posts`.
221
214
222
-
**Note**: you may have a blank page if your database does not have any record yet. Make sure to create some using Supabase Studio.
215
+
**Note**: You may have a blank page if your database does not have any record yet. Make sure to create some using Supabase Studio.
223
216
224
217
Note that the Supabase credentials never leave the server. It's up to you to add your own authentication to the API proxy.
225
218
226
219
## Sourcemaps in production
227
220
228
221
By default, Vite won't include the TypeScript sourcemaps in production builds. This means you'll only have the react-admin ESM builds for debugging.
222
+
229
223
Should you prefer to have the TypeScript sources, you'll have to configure some Vite aliases:
Copy file name to clipboardExpand all lines: docs/Remix.md
+27-28Lines changed: 27 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ title: "Remix Integration"
7
7
8
8
[Remix](https://remix.run/) is a Node.js framework for server-side-rendered React apps. But even if react-admin is designed to build Single-Page Applications, Remix and react-admin integrate seamlessly.
9
9
10
-
These instructions are targeting Remix v2.
10
+
These instructions are targeting Remix v2. For Remix v3 check out the [React Router Framework Integration](ReactRouterFramework.md) guide.
11
11
12
12
## Setting Up Remix
13
13
@@ -44,19 +44,19 @@ import { defineConfig } from "vite";
44
44
import tsconfigPaths from "vite-tsconfig-paths";
45
45
46
46
export default defineConfig({
47
-
plugins: [
48
-
remix({
49
-
future: {
50
-
v3_fetcherPersist: true,
51
-
v3_relativeSplatPath: true,
52
-
v3_throwAbortReason: true,
53
-
},
54
-
}),
55
-
tsconfigPaths(),
56
-
],
57
-
+ssr: {
58
-
+noExternal: ['ra-data-json-server'] // or the dataProvider you are using
59
-
+},
47
+
plugins: [
48
+
remix({
49
+
future: {
50
+
v3_fetcherPersist: true,
51
+
v3_relativeSplatPath: true,
52
+
v3_throwAbortReason: true,
53
+
},
54
+
}),
55
+
tsconfigPaths(),
56
+
],
57
+
+ssr: {
58
+
+noExternal: ['ra-data-json-server'] // or the dataProvider you are using
0 commit comments