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

1

5

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

Exurb answered 8/8, 2019 at 1:20 Comment(0)
N
7

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;
Nutgall answered 8/8, 2019 at 3:56 Comment(1)
Exactly what I'm looking for! Thanks.Exurb

© 2022 - 2024 — McMap. All rights reserved.