我正在使用 react-admin
.
我替换/更改了<DashboardMenuItem>
至 <MenuItemLink>
(概述)。
不幸的是,这个“概览”出现active
一直被选中。
知道如何在选择另一个菜单项时将其停用吗?
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}
/>
最佳答案
根据 react-router documentation ,您可以通过将 Prop exact
添加到链接组件来做到这一点:
<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
/>
关于reactjs - React-Admin:<MenuItemLink> 始终显示为 `active`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60709591/