From c66f086f426a9618c2b0711254cc629848827189 Mon Sep 17 00:00:00 2001 From: Baorong Li Date: Sat, 5 May 2018 12:11:03 +0800 Subject: [PATCH] fix #372 update navOpenKeys when copy link open --- src/components/Layout/Menu.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 4d9ad6a..015c27f 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -5,6 +5,9 @@ import { Link } from 'react-router-dom' import { arrayToTree, queryArray } from 'utils' import pathToRegexp from 'path-to-regexp' +const { SubMenu } = Menu +let openKeysFlag = false + const Menus = ({ siderFold, darkTheme, navOpenKeys, changeOpenKeys, menu, location, }) => { @@ -20,7 +23,7 @@ const Menus = ({ levelMap[item.id] = item.mpid } return ( - {item.icon && } @@ -28,7 +31,7 @@ const Menus = ({ } > {getMenus(item.children, siderFoldN)} - + ) } return ( @@ -62,6 +65,7 @@ const Menus = ({ } const onOpenChange = (openKeys) => { + if (navOpenKeys.length) changeOpenKeys([]), openKeysFlag = true const latestOpenKey = openKeys.find(key => !navOpenKeys.includes(key)) const latestCloseKey = navOpenKeys.find(key => !openKeys.includes(key)) let nextOpenKeys = [] @@ -85,6 +89,7 @@ const Menus = ({ let defaultSelectedKeys for (let item of menu) { if (item.route && pathToRegexp(item.route).exec(location.pathname)) { + if (!navOpenKeys.length && item.mpid && !openKeysFlag) changeOpenKeys([String(item.mpid)]) currentMenu = item break }