Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Admin: <MenuItemLink> always appears as `active`

Am using react-admin.
I replaced/changed the <DashboardMenuItem> to <MenuItemLink> (overview).

Unfortunately, this "overview" appears active selected all the time.
Any idea how to deactivate it when another menu item is selected?

Dashboard image

In the attached image, notice that "Overview" and "Reviews" appear to be selected (active)

// Removed this line...
- <DashboardMenuItem onClick={onMenuClick} sidebarIsOpen={open} />

// And replaced it with this...
+ <MenuItemLink
    to={`/`} // by default `react-admin` renders Dashboard on this route
    primaryText={translate(`resources.overview.name`, {
      smart_count: 2
    })}
    leftIcon={<DashboardIcon />}
    onClick={onMenuClick}
    sidebarIsOpen={open}
    dense={dense}
/>
like image 525
Rizwan Ahmed Shivalli Avatar asked Mar 12 '26 20:03

Rizwan Ahmed Shivalli


1 Answers

According to react-router documentation, you can do that by add props exact to the link component:

<MenuItemLink
    to={`/`} // by default `react-admin` renders Dashboard on this route
    primaryText={translate(`resources.overview.name`, {
      smart_count: 2
    })}
    leftIcon={<DashboardIcon />}
    onClick={onMenuClick}
    sidebarIsOpen={open}
    dense={dense}
    exact
/>
like image 188
Fikri Amri Avatar answered Mar 15 '26 03:03

Fikri Amri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!