Ant Design Pro工程中修改src/layouts/BasicLayout.jsx中的menuItemRender这个prop即可实现在移动模式下点击条目以后自动关闭菜单

src/layouts/BasicLayout.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const BasicLayout = props => {
return (
<ProLayout
menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl) {
return defaultDom;
}
const linkClick = menuItemProps.isMobile === true ? (handleMenuCollapse) : undefined;
return <Link to={menuItemProps.path} onClick={linkClick}>{defaultDom}</Link>;
}}
>
</ProLayout>
);
};