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
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/guides/Routing.md
+34-40Lines changed: 34 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,21 @@
1
1
---
2
-
layout: default
3
-
title: "Routing in React-Admin Apps"
2
+
title: "Routing"
4
3
---
5
4
6
-
# Routing
7
-
8
-
React-admin uses [the react-router library](https://reactrouter.com/) to handle routing. This allows to use different routing strategies, and to integrate a react-admin app inside another app.
5
+
Ra-core uses [the react-router library](https://reactrouter.com/) to handle routing. This allows to use different routing strategies, and to integrate an ra-core app inside another app.
9
6
10
7
## Route Structure
11
8
12
-
For each `<Resource>`, react-admin creates 4 routes:
9
+
For each `<Resource>`, ra-core creates 4 routes:
13
10
14
11
*`/:resource`: the list page
15
12
*`/:resource/create`: the create page
16
13
*`/:resource/:id/edit`: the edit page
17
14
*`/:resource/:id/show`: the show page
18
15
19
-
These routes are fixed (i.e. they cannot be changed via configuration). Having constant routing rules allow react-admin to handle cross-resource links natively.
16
+
These routes are fixed (i.e. they cannot be changed via configuration). Having constant routing rules allow ra-core to handle cross-resource links natively.
20
17
21
-
**Tip**: React-admin allows to use resource names containing slashes, e.g. 'cms/categories'.
18
+
**Tip**: Ra-core allows to use resource names containing slashes, e.g. 'cms/categories'.
22
19
23
20
## Linking To A Page
24
21
@@ -37,11 +34,11 @@ const Dashboard = () => (
37
34
);
38
35
```
39
36
40
-
Internally, react-admin uses a helper to build links, to allow mounting react-admin apps inside an existing app. You can use this helper, `useCreatePath`, in your components, if they have to work in admins mounted in a sub path:
37
+
Internally, ra-core uses a helper to build links, to allow mounting ra-core apps inside an existing app. You can use this helper, `useCreatePath`, in your components, if they have to work in admins mounted in a sub path:
In addition to CRUD pages for resources, you can create as many routes as you want for your custom pages. Use [the `<CustomRoutes>` component](./CustomRoutes.md) to do so.
95
+
In addition to CRUD pages for resources, you can create as many routes as you want for your custom pages. Use [the `<CustomRoutes>` component](../app-configuration/CustomRoutes.md) to do so.
React-admin uses [the react-router library](https://reactrouter.com/) to handle routing, with a [HashRouter](https://reactrouter.com/en/routers/create-hash-router). This means that the hash portion of the URL (i.e. `#/posts/123` in the example) contains the main application route. This strategy has the benefit of working without a server, and with legacy web browsers.
123
+
Ra-core uses [the react-router library](https://reactrouter.com/) to handle routing, with a [HashRouter](https://reactrouter.com/en/routers/create-hash-router). This means that the hash portion of the URL (i.e. `#/posts/123` in the example) contains the main application route. This strategy has the benefit of working without a server, and with legacy web browsers.
129
124
130
-
But you may want to use another routing strategy, e.g. to allow server-side rendering of individual pages. React-router offers various Router components to implement such routing strategies. If you want to use a different router, simply put your app in a create router function. React-admin will detect that it's already inside a router, and skip its own router.
125
+
But you may want to use another routing strategy, e.g. to allow server-side rendering of individual pages. React-router offers various Router components to implement such routing strategies. If you want to use a different router, simply put your app in a create router function. Ra-core will detect that it's already inside a router, and skip its own router.
React-admin links are absolute (e.g. `/posts/123/show`). If you serve your admin from a sub path (e.g. `/admin`), react-admin works seamlessly as it only appends a hash (URLs will look like `/admin#/posts/123/show`).
149
+
Ra-core links are absolute (e.g. `/posts/123/show`). If you serve your admin from a sub path (e.g. `/admin`), ra-core works seamlessly as it only appends a hash (URLs will look like `/admin#/posts/123/show`).
155
150
156
-
However, if you serve your admin from a sub path AND use another Router (like [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router) for instance), you need to set the [`opts.basename`](https://reactrouter.com/en/main/routers/create-browser-router#optsbasename) of `createBrowserRouter` function, so that react-admin routes include the basename in all links (e.g. `/admin/posts/123/show`).
151
+
However, if you serve your admin from a sub path AND use another Router (like [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router) for instance), you need to set the [`opts.basename`](https://reactrouter.com/en/main/routers/create-browser-router#optsbasename) of `createBrowserRouter` function, so that ra-core routes include the basename in all links (e.g. `/admin/posts/123/show`).
@@ -182,11 +177,11 @@ This makes all links be prefixed with `/admin`.
182
177
183
178
Note that it is your responsibility to serve the admin from the sub path, e.g. by setting the `base` field in `vite.config.ts` if you use [Vite.js](https://vitejs.dev/config/shared-options.html#base), or the `homepage` field in `package.json` if you use [Create React App](https://create-react-app.dev/docs/deployment/#building-for-relative-paths).
184
179
185
-
If you want to use react-admin as a sub path of a larger React application, check the next section for instructions.
180
+
If you want to use ra-core as a sub path of a larger React application, check the next section for instructions.
186
181
187
-
## Using React-Admin Inside a Route
182
+
## Using Ra-Core Inside a Route
188
183
189
-
You can include a react-admin app inside another app, using a react-router `<Route>`:
184
+
You can include an ra-core app inside another app, using a react-router `<Route>`:
This will let react-admin build absolute URLs including the sub path.
224
+
This will let ra-core build absolute URLs including the sub path.
230
225
231
226
## Troubleshooting
232
227
@@ -250,11 +245,11 @@ or
250
245
251
246
> `<Route>` may be used only in the context of a `<Router>` component
252
247
253
-
These errors can happen if you added `react-router` and/or `react-router-dom` to your dependencies, and didn't use the same version as react-admin. In that case, your application has two versions of react-router, and the calls you add can't see the react-admin routing context.
248
+
These errors can happen if you added `react-router` and/or `react-router-dom` to your dependencies, and didn't use the same version as ra-core. In that case, your application has two versions of react-router, and the calls you add can't see the ra-core routing context.
254
249
255
250
You can use the `npm list react-router` and `npm list react-router-dom` commands to check which versions are installed.
256
251
257
-
If there are duplicates, you need to make sure to use only the same version as react-admin. You can deduplicate them using yarn's `resolutions` or npm's `overrides`.
252
+
If there are duplicates, you need to make sure to use only the same version as ra-core. You can deduplicate them using yarn's `resolutions` or npm's `overrides`.
258
253
259
254
```js
260
255
// in packages.json
@@ -267,4 +262,3 @@ If there are duplicates, you need to make sure to use only the same version as r
267
262
}
268
263
```
269
264
270
-
This may also happen inside a [Remix](https://remix.run/) application. See [Setting up react-admin for Remix](./Remix.md#setting-up-react-admin-in-remix) for instructions to overcome that problem.
0 commit comments