const [openKey, setOpenKey] = useState([]);
// 解决用户体验bug
useEffect(() => {
newItems.map((v) => { //遍历路由表
if (v.children) { //判断是否存在子路由
v.children.some((i) => { //检索满足条件的第一项返回
if (location.pathname.indexOf(i.key) === 0) {
setOpenKey([v.key]); //把满足条件的值赋给openKey
}
});
}
});
}, [location.pathname]);
<Menu openKeys={openKey} /> //组件展开
antd组件库进入界面默认展开所在区域二级菜单思路--用户体验bug解决方法
最新推荐文章于 2024-05-11 02:10:19 发布