I need a resource with all its configuration, but I don't want it to be showed in sidebar
Asked
Active
Viewed 5,221 times
4 Answers
8
You can omit the list prop for a Resource if you want to hide it in the sidebar menu.
<Resource name="posts" />

TextMode
- 91
- 1
- 3
-
1solution was simple enough to work for my case. Indeed omitting the list prop workes, and you won't have to worry with creating a custom menu, until the day you'll have to cross that bridge. – ChampR Sep 18 '18 at 13:02
-
1If I am omitting the list prop then no URL is getting called and a blank page is coming – Manish Kumar Nov 21 '19 at 11:59
-
Could you please add the corresponding `import` in the answer? Is it `import { Resource } from 'react-admin'`? – A.L Jun 05 '23 at 15:54
4
I found a different "hacky" way You can add in your css the following to hide from the menu the resource
.MuiDrawer-root a[href^='#/resource-to-exclude'] {
display: none;
}

Daniel Jakobsen Hallel
- 566
- 1
- 5
- 18
2
As explained in the documentation, you can provide your Menu
component to the Admin
component using it's menu
prop. See
https://marmelab.com/react-admin/Admin.html#menu
Please note that this prop will be deprecated soon in favor of appLayout
but you'll still use this custom menu in your custom layout anyway.
// in src/Menu.js
import React from 'react';
import { connect } from 'react-redux';
import { MenuItemLink, getResources } from 'react-admin';
import { withRouter } from 'react-router-dom';
import Responsive from '../layout/Responsive';
const Menu = ({ resources, onMenuClick, logout }) => (
<div>
{resources
.filter(resource => resource.name !== 'excluded-resource')
.map(resource => (
<MenuItemLink to={`/${resource.name}`} primaryText={resource.name} onClick={onMenuClick} />
))
}
<Responsive
small={logout}
medium={null} // Pass null to render nothing on larger devices
/>
</div>
);
const mapStateToProps = state => ({
// Rerieve all known resources
resources: getResources(state),
});
export default withRouter(connect(mapStateToProps)(Menu));

Gildas Garcia
- 6,966
- 3
- 15
- 29
-
Side note about the `App` component `menu` prop: https://github.com/marmelab/react-admin/pull/1881 – Gildas Garcia Jun 20 '18 at 08:42
0
If your goal is to hide the entire sidebar, and make it not visible to the user, in your theme.js
try add the following code:
RaSidebar: {
drawerPaper: {
display: 'none',
},
},
eg.
const baseTheme = createTheme({
overrides: {
...<components you want override etc>...,
// React-admin
RaSidebar: {
drawerPaper: {
display: 'none',
},
},
},
});

ezennnn
- 1,239
- 11
- 13