reactjsadmin-on-rest

admin on rest hide resource component in sidebar


I need a resource with all its configuration, but I don't want it to be showed in sidebar enter image description here


Solution

  • 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));