修复左侧栏菜单在key相同时,会同时选中bug

This commit is contained in:
pmg1989
2017-03-16 14:58:20 +08:00
parent df1b53130f
commit 6ab878061d
2 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -159,9 +159,9 @@
.ant-menu-sub {
height: 0;
opacity: 0;
overflow: hidden;
transition: none;
}
.ant-menu-submenu-active {
.ant-menu-sub {
height: auto;
+8 -8
View File
@@ -4,19 +4,19 @@ import { Link } from 'dva/router'
import { menu } from '../../utils'
const topMenus = menu.map(item => item.key)
const getMenus = function (menuArray, siderFold, parentPath) {
parentPath = parentPath || '/'
const getMenus = function (menuArray, siderFold, parentPath = '/') {
return menuArray.map(item => {
const linkTo = parentPath +item.key
if (item.child) {
return (
<Menu.SubMenu key={item.key} title={<span>{item.icon ? <Icon type={item.icon} /> : ''}{siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name}</span>}>
{getMenus(item.child, siderFold, `${parentPath}${item.key}/`)}
<Menu.SubMenu key={linkTo} title={<span>{item.icon ? <Icon type={item.icon} /> : ''}{siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name}</span>}>
{getMenus(item.child, siderFold, `${linkTo}/`)}
</Menu.SubMenu>
)
}
return (
<Menu.Item key={item.key}>
<Link to={parentPath + item.key}>
<Menu.Item key={linkTo}>
<Link to={linkTo}>
{item.icon ? <Icon type={item.icon} /> : ''}
{siderFold && topMenus.indexOf(item.key) >= 0 ? '' : item.name}
</Link>
@@ -30,7 +30,7 @@ function Menus ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKey
const getAncestorKeys = (key) => {
const map = {
navigation2: ['navigation'],
'/navigation/navigation2': ['/navigation'],
}
return map[key] || []
}
@@ -59,7 +59,7 @@ function Menus ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKey
mode={siderFold ? 'vertical' : 'inline'}
theme={darkTheme ? 'dark' : 'light'}
onClick={handleClickNavMenu}
defaultSelectedKeys={[location.pathname.split('/')[location.pathname.split('/').length - 1] || 'dashboard']}
defaultSelectedKeys={[location.pathname !== "/" ? location.pathname : '/dashboard']}
>
{menuItems}
</Menu>