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
Now, when a user browses to `/settings` or `/profile`, the components you defined will appear in the main part of the screen.
41
41
42
+
**Tip**: Custom routes don't automatically appear in the menu. You have to manually [customize the menu](#adding-custom-routes-to-the-menu) if you want custom routes to be accessible from the menu.
43
+
42
44
## `children`
43
45
44
-
`children` of the `<CustomRoutes>` component must be `<Route>` elements from [react-router-dom](https://reactrouter.com/en/6/start/concepts#defining-routes), and map a path with a custom element.
46
+
`children` of the `<CustomRoutes>` component must be `<Route>` elements from [react-router-dom](https://reactrouter.com/en/6/start/concepts#defining-routes), mapping a `path` with a custom `element`.
You can learn more about the `<Route>` element in the [react-router-dom documentation](https://reactrouter.com/en/6/start/concepts#defining-routes).
70
+
67
71
## `noLayout`
68
72
69
-
By default, custom routes render within the application layout (with the menu and the app bar). If you want a custom route to render without the layout, e.g. for registration screens, then provide the `noLayout` prop on the `<CustomRoutes>` element:
73
+
By default, custom routes render within the application layout. If you want a custom route to render without the layout, e.g. for registration screens, then provide the `noLayout` prop on the `<CustomRoutes>` element.
74
+
75
+
<imgsrc="./img/custom-route-nolayout.png"class="no-shadow"alt="custom route with no layout" />
76
+
77
+
Here is an example of application configuration mixing custom routes with and without layout:
70
78
71
79
```jsx
72
80
// in src/App.js
73
81
import { Admin, CustomRoutes } from'react-admin';
74
82
import { Route } from"react-router-dom";
75
83
76
-
importdataProviderfrom'./dataProvider';
77
-
importRegisterfrom'./Register';
78
-
importSettingsfrom'./Settings';
79
-
importProfilefrom'./Profile';
84
+
import{ dataProvider }from'./dataProvider';
85
+
import{ Register }from'./Register';
86
+
import{ Settings }from'./Settings';
87
+
import{ Profile }from'./Profile';
80
88
81
89
constApp= () => (
82
90
<Admin dataProvider={dataProvider}>
@@ -93,9 +101,13 @@ const App = () => (
93
101
94
102
As illustrated above, there can be more than one `<CustomRoutes>` element inside an `<Admin>` component.
95
103
96
-
## Custom Page Title
104
+
## Customizing The Page Title
97
105
98
-
To define the page title (displayed in the app bar), your custom pages can use [the `<Title>` component](./Title.md) from react-admin:
106
+
To define the page title (displayed in the app bar), custom pages should use [the `<Title>` component](./Title.md).
`<Title>` uses a [React Portal](https://react.dev/reference/react-dom/createPortal), so it doesn't matter *where* you put it in your component. The title will always be rendered in the app bar.
119
131
120
-
## Linking To Custom Routes
132
+
## Adding Custom Routes to the Menu
121
133
122
-
You can link to your pages using [react-router's Link component](https://reactrouter.com/en/main/components/link):
134
+
To add your custom pages to the navigation menu, you have to replace the default menu by a [custom menu](./Menu.md) with entries for the custom pages.
To learn more about custom menus, check [the `<Menu>` documentation](./Menu.md).
190
+
191
+
## Linking To Custom Routes
192
+
193
+
You can link to your pages using [react-router's Link component](https://reactrouter.com/en/main/components/link). Make sure to use the same value in the `<Link to>` prop as in the `<Route path>` prop.
If you want to add sub-routes to a resource, add the `<Route>` elements as [children of the `<Resource>` element](./Resource.md#children):
208
+
Sometimes you want to add more routes to a resource path. For instance, you may want to add a custom page to the `/posts` resource, such as `/posts/analytics`.
209
+
210
+
To do so, add the `<Route>` elements as [children of the `<Resource>` element](./Resource.md#children):
0 commit comments