问题
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
回答1:
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;
来源:https://stackoverflow.com/questions/57404053/react-admin-create-a-custom-page-which-can-be-accessed-from-menu-sidebar