Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 288
Yaiba Avatar asked Aug 08 '19 01:08

Yaiba


People also ask

How do I add a custom menu in react-admin?

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.

How to create custom layout components in react-admin?

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.

How to customize the homepage of an admin app in react?

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.

How do I add custom routes before the react-admin ones?

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.


1 Answers

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;
like image 189
MaxAlex Avatar answered Oct 12 '22 23:10

MaxAlex