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
By default, React-admin uses the list of `<Resource>` components passed as children of `<Admin>` to build a menu to each resource with a `list` component.
810
+
By default, React-admin uses the list of `<Resource>` components passed as children of `<Admin>` to build a menu to each resource with a `list` component. If you want to reorder, add or remove menu items, for instance to link to non-resources pages, you have to provide a custom `<Menu>` component to your `Layout`.
811
811
812
-
If you want to add or remove menu items, for instance to link to non-resources pages, you can create your own menu component:
812
+
### Custom Menu Example
813
+
814
+
You can create a custom menu component using the `<DashboardMenuItem>` and `<MenuItemLink>` components:
**Tip**: Note the `MenuItemLink` component. It must be used to avoid unwanted side effects in mobile views.
897
+
**Tip**: If you need a multi-level menu, or a Mega Menu opening panels with custom content, check out [the `ra-navigation`<imgclass="icon"src="./img/premium.svg" /> module](https://marmelab.com/ra-enterprise/modules/ra-navigation) (part of the [Enterprise Edition](https://marmelab.com/ra-enterprise))
862
898
863
-
**Tip**: Note that we include the `logout`item only on small devices. Indeed, the `logout` button is already displayed in the AppBar on larger devices.
**Tip**: The `primaryText` prop accepts a React node. You can pass a custom element in it. For example:
901
+

866
902
867
-
```jsx
868
-
importBadgefrom'@material-ui/core/Badge';
903
+
### `<MenuItemLink>`
869
904
870
-
<MenuItemLink to="/custom-route" primaryText={
871
-
<Badge badgeContent={4} color="primary">
872
-
Notifications
873
-
</Badge>
874
-
} onClick={onMenuClick} />
875
-
```
905
+
The `<MenuItemLink>` component displays a menu item with a label and an icon - or only the icon with a tooltip when the sidebar is minimized. It also handles the automatic closing of the menu on tap on mobile.
876
906
877
-
To use this custom menu component, pass it to a custom Layout, as explained above:
907
+
The `primaryText` prop accepts a string or a React node. You can use it e.g. to display a badge on top of the menu item:
**Tip**: The `<MenuItemLink>` component makes use of the React Router [NavLink](https://reacttraining.com/react-router/web/api/NavLink) component, hence allowing to customize the active menu style. For instance, here is how to use a custom theme to show a left border for the active menu:
924
+
925
+
```jsx
926
+
exportconsttheme= {
927
+
palette: {
897
928
// ...
898
-
</Admin>
899
-
);
929
+
},
930
+
overrides: {
931
+
RaMenuItemLink: {
932
+
active: {
933
+
borderLeft:'3px solid #4f3cc9',
934
+
},
935
+
root: {
936
+
borderLeft:'3px solid #fff', // invisible menu when not active, to avoid scrolling the text when selecting the menu
937
+
},
938
+
},
939
+
},
940
+
};
900
941
```
901
942
902
-
**Tip**: If you use authentication, don't forget to render the `logout` prop in your custom menu component. Also, the `onMenuClick` function passed as prop is used to close the sidebar on mobile.
943
+
### Menu To A Filtered List
903
944
904
-
The `MenuItemLink` component make use of the React Router [NavLink](https://reacttraining.com/react-router/web/api/NavLink) component, hence allowing to customize its style when it targets the current page.
945
+
As the filter values are taken from the URL, you can link to a pre-filtered list by setting the `filter` query parameter.
905
946
906
-
**Tip**: If you need a multi-level menu, or a Mega Menu opening panels with custom content, check out [the `ra-navigation`<imgclass="icon"src="./img/premium.svg" /> module](https://marmelab.com/ra-enterprise/modules/ra-navigation) (part of the [Enterprise Edition](https://marmelab.com/ra-enterprise))
947
+
For instance, to include a menu to a list of published posts:

960
+
### Menu To A List Without Filters
961
+
962
+
By default, a click on `<MenuItemLink >` for a list page opens the list with the same filters as they were applied the last time the user saw them. This is usually the expected behavior, but your users may prefer that clicking on a menu item resets the list filters.
963
+
964
+
Just use an empty `filter` query parameter to force empty filters:
965
+
966
+
```jsx
967
+
<MenuItemLink
968
+
to="/posts?filter=%7B%7D"// %7B%7D is JSON.stringify({})
0 commit comments