Skip to content

Commit 0a18b80

Browse files
committed
Fix paths and imports
1 parent 0efa42d commit 0a18b80

File tree

2 files changed

+56
-58
lines changed

2 files changed

+56
-58
lines changed

docs/ReactRouterFramework.md

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: "React Router Framework Integration"
55

66
# React Router Framework Integration
77

8-
[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.
99

1010
These instructions are targeting React Router v7 in Framework mode.
1111

@@ -25,13 +25,13 @@ This script will ask you for more details about your project. You can use the fo
2525

2626
## Setting Up React-Admin In React Router
2727

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).
2929

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`.
3131

3232
```sh
3333
cd react-router-admin
34-
npm add react-[email protected] react-admin ra-data-json-server
34+
npm add react-admin ra-data-json-server [email protected]
3535
```
3636

3737
## Adding React-Admin In A Sub Route
@@ -49,7 +49,7 @@ export default [
4949
] satisfies RouteConfig;
5050
```
5151

52-
Now create the `routes/admin.tsx` file:
52+
Now create the `app/routes/admin.tsx` file:
5353

5454
```tsx
5555
import { Admin, Resource, ListGuesser } from "react-admin";
@@ -67,9 +67,9 @@ export default function App() {
6767
}
6868
```
6969

70-
**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:
7171

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/>.
7373

7474
## Adding an API
7575

@@ -86,9 +86,11 @@ First, create a Supabase REST API and its associated PostgreSQL database directl
8686
- `posts` with fields: `id`, `title`, and `body`
8787
- `comments` with fields: `id`, `name`, `body`, and `postId` (a foreign key to the `posts.id` field)
8888

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.
9090

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:
9294

9395
```sh
9496
# In `.env`
@@ -113,7 +115,7 @@ export default [
113115
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.
114116

115117
```tsx
116-
// in /app/routes/admin.api.$.tsx
118+
// in app/routes/admin.api.tsx
117119
import type { Route } from "./+types/admin.api";
118120

119121
// handle read requests (getOne, getList, getMany, getManyReference)
@@ -169,33 +171,24 @@ npm add @raphiniert/ra-data-postgrest
169171

170172
Update your `vite.config.ts` to add `@raphiniert/ra-data-postgrest` to the `noExternal` array:
171173

172-
173174
```diff
174-
import { vitePlugin as remix } from "@remix-run/dev";
175+
import { reactRouter } from "@react-router/dev/vite";
176+
import tailwindcss from "@tailwindcss/vite";
175177
import { defineConfig } from "vite";
176178
import tsconfigPaths from "vite-tsconfig-paths";
177179

178180
export default defineConfig({
179-
plugins: [
180-
remix({
181-
future: {
182-
v3_fetcherPersist: true,
183-
v3_relativeSplatPath: true,
184-
v3_throwAbortReason: true,
185-
},
186-
}),
187-
tsconfigPaths(),
188-
],
189-
+ ssr: {
190-
+ noExternal: ['@raphiniert/ra-data-postgrest']
191-
+ },
181+
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
182+
+ ssr: {
183+
+ noExternal: ['@raphiniert/ra-data-postgrest']
184+
+ },
192185
});
193186
```
194187

195188
Finally, update your Admin dataProvider:
196189

197190
```jsx
198-
// in app/routes/admin.$.tsx
191+
// in app/routes/admin.tsx
199192
import { Admin, Resource, ListGuesser, fetchUtils } from "react-admin";
200193
import postgrestRestProvider, { defaultPrimaryKeys, defaultSchema } from '@raphiniert/ra-data-postgrest';
201194

@@ -217,22 +210,25 @@ export default function App() {
217210
}
218211
```
219212

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`.
221214

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.
223216

224217
Note that the Supabase credentials never leave the server. It's up to you to add your own authentication to the API proxy.
225218

226219
## Sourcemaps in production
227220

228221
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+
229223
Should you prefer to have the TypeScript sources, you'll have to configure some Vite aliases:
230224

231225
```tsx
232226
// in vite.config.ts
227+
import { reactRouter } from "@react-router/dev/vite";
228+
import tailwindcss from "@tailwindcss/vite";
233229
import { defineConfig } from "vite";
230+
import tsconfigPaths from "vite-tsconfig-paths";
234231
import path from "path";
235-
import react from "@vitejs/plugin-react";
236232

237233
const alias = [
238234
{ find: 'react-admin', replacement: path.resolve(__dirname, './node_modules/react-admin/src') },
@@ -242,7 +238,10 @@ const alias = [
242238
]
243239

244240
export default defineConfig({
245-
plugins: [react()],
241+
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
242+
ssr: {
243+
noExternal: ['@raphiniert/ra-data-postgrest']
244+
},
246245
build: { sourcemap: true },
247246
resolve: { alias },
248247
});

docs/Remix.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: "Remix Integration"
77

88
[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.
99

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.
1111

1212
## Setting Up Remix
1313

@@ -44,19 +44,19 @@ import { defineConfig } from "vite";
4444
import tsconfigPaths from "vite-tsconfig-paths";
4545

4646
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
59+
+ },
6060
});
6161
```
6262

@@ -189,26 +189,25 @@ npm add @raphiniert/ra-data-postgrest
189189

190190
Update your `vite.config.ts` to add `@raphiniert/ra-data-postgrest` to the `noExternal` array:
191191

192-
193192
```diff
194193
import { vitePlugin as remix } from "@remix-run/dev";
195194
import { defineConfig } from "vite";
196195
import tsconfigPaths from "vite-tsconfig-paths";
197196

198197
export default defineConfig({
199-
plugins: [
200-
remix({
201-
future: {
202-
v3_fetcherPersist: true,
203-
v3_relativeSplatPath: true,
204-
v3_throwAbortReason: true,
205-
},
206-
}),
207-
tsconfigPaths(),
208-
],
209-
+ ssr: {
210-
+ noExternal: ['@raphiniert/ra-data-postgrest']
211-
+ },
198+
plugins: [
199+
remix({
200+
future: {
201+
v3_fetcherPersist: true,
202+
v3_relativeSplatPath: true,
203+
v3_throwAbortReason: true,
204+
},
205+
}),
206+
tsconfigPaths(),
207+
],
208+
+ ssr: {
209+
+ noExternal: ['@raphiniert/ra-data-postgrest']
210+
+ },
212211
});
213212
```
214213

0 commit comments

Comments
 (0)