Commit e78d7128 authored by XieZhiXiong's avatar XieZhiXiong

完善菜单 openKeys 逻辑

parent 87e75412
......@@ -113,18 +113,23 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
}, [location.pathname]);
// 当 currentRouter 改变时(路由触发所致),设置 Menu openKeys 为 currentRouter 的祖先路由记录
// 当 菜单 收缩时 收起所有菜单,打开执行上面的逻辑
// 这里处理的逻辑都是由 路由改变 引起的,需要配合 点击 SubMenu 也是需要设置一遍 openKeys 一起达到理想的效果
// 注:点击 SubMenu 不会触发路由跳转
useEffect(() => {
if (menuRouter && menuRouter.children && currentRouter) {
if (collapsed) {
setOpenKeys([])
} else {
// 优化默认打开的菜单
setOpenKeys([...openKeys, currentRouter.key, ...currentRouter.pro_layout_parentKeys])
// setOpenKeys([...openKeys, currentRouter.key, ...currentRouter.pro_layout_parentKeys])
setOpenKeys(currentRouter.pro_layout_parentKeys)
}
} else {
setOpenKeys([])
}
}, [currentRouter, location.pathname, collapsed])
}, [currentRouter, collapsed])
return (
<ProLayout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment