I'm new to react-admin, how can I create a custom page that can access from menu sidebar? What I'm looking for is similar to this tutorial: https://marmelab.com/blog/2019/03/07/react-admin-advanced-recipes-user-profile.html but I need to be able to access that Profile page from an icon in left menu sidebar just like other Resource. Thanks
Using a Custom Menu 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.
If you want to deeply customize the app header, the menu, or the notifications, the best way is to provide a custom layout component. It must contain a {children} placeholder, where react-admin will render the resources. If you use material UI fields and inputs, it should contain a <ThemeProvider> element.
On error pages, the header of an admin app uses ‘React Admin’ as the main app title. Use the title to customize it. By default, the homepage of an admin app is the list of the first child <Resource>. But you can also specify a custom component instead.
To add custom routes before the react-admin ones, and therefore override the default resource routes, use the customRoutes prop instead. Tip: This prop is deprecated. To override the menu component, use a custom layout instead.
You need to use your menu component:
import React from 'react';
import { Layout, MenuItemLink, Responsive } from 'react-admin';
import MyAppbar from './MyAppbar';
import BookIcon from '@material-ui/icons/Book';
import SettingsIcon from '@material-ui/icons/Settings';
import ChatBubbleIcon from '@material-ui/icons/ChatBubble';
import LabelIcon from '@material-ui/icons/Label';
const menuItems = [
{ name: 'posts', text: 'Posts', icon: <BookIcon /> },
{ name: 'comments', text: 'Comments', icon: <ChatBubbleIcon /> },
{ name: 'tags', text: 'Tags', icon: <LabelIcon /> },
{ name: 'my-profile', text: 'My profile', icon: <SettingsIcon /> }
];
const MyMenu = ({ onMenuClick, logout }) => (
<div>
{ menuItems.map(item => (
<MenuItemLink
key={item.name}
to={`/${item.name}`}
primaryText={item.text}
leftIcon={item.icon}
onClick={onMenuClick}
/>
))}
<Responsive
small={logout}
medium={null}
/>
</div>
);
const MyLayout = props => <Layout {...props} menu={MyMenu} appBar={MyAppbar} />;
export default MyLayout;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With