coreui-free-react-admin-template icon indicating copy to clipboard operation
coreui-free-react-admin-template copied to clipboard

Showing sidebar items by roles

Open ghost opened this issue 8 years ago • 3 comments

First i want to say this template is really nice, my thing is i want to show the items on the sidebar deping on redux state for user roles, somthing like if((this.state.user.rol).includes('admin'){ ///... show side var items }

ghost avatar Apr 21 '18 18:04 ghost

have you got solutions for this ? if yes please post it here

AbhaysinghBhosale avatar Aug 23 '18 05:08 AbhaysinghBhosale

you can create your new navbar item list in src/_nav.js.

const customNav1 = {
  items: [
    {
      name: 'Dashboard',
      url: '/dashboard',
      icon: 'icon-speedometer',
      badge: {
        variant: 'info',
        text: 'NEW',
      },
    },
  ]
};

then import it to src/containers/DefaultLayout/DefaultLayout.js by changing few codes

//from
import navigation from '../../_nav';
//to
import {customNav1, customNav2} from '../../_nav';

then in render method, add some logic before return statement

if (isAdmin)
  navigation = customNav1;
else
  navigation = customNav2;

anantadwi13 avatar May 16 '19 16:05 anantadwi13

thanks so much @anantadwi13 , just need to put export for a variable to be exported in _nav

axle21 avatar Oct 01 '19 04:10 axle21