react-admin Create a custom page which can be accessed from menu sidebar

▼魔方 西西 提交于 2020-01-02 11:43:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!