Commit c1c36b61 authored by jim's avatar jim

Fix menu click exception

parent 2c0e700f
......@@ -2,9 +2,7 @@ const path = require('path');
export default {
entry: 'src/index.js',
extraBabelPlugins: [
['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
],
extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
env: {
development: {
extraBabelPlugins: ['dva-hmr'],
......@@ -19,5 +17,6 @@ export default {
template: './src/index.ejs',
},
publicPath: '/',
disableDynamicImport: true,
hash: true,
};
......@@ -136,7 +136,7 @@ class Sidebar extends PureComponent {
<DrawerMenu
parent={null}
level={null}
iconChild={null}
handleChild={null}
open={collapse}
placement="right"
width="336px"
......
......@@ -65,16 +65,22 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) =>
);
export default class SiderMenu extends PureComponent {
static getDerivedStateFromProps(nextProps) {
return {
openKeys: getDefaultCollapsedSubMenus(nextProps),
};
static getDerivedStateFromProps(props, state) {
const { pathname } = state;
if (props.location.pathname !== pathname) {
return {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props),
};
}
return null;
}
constructor(props) {
super(props);
this.menus = props.menuData;
this.flatMenuKeys = getFlatMenuKeys(props.menuData);
this.state = {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props),
};
}
......@@ -113,7 +119,7 @@ export default class SiderMenu extends PureComponent {
<Link
to={itemPath}
target={target}
replace={itemPath === this.props.location.pathname}
replace={itemPath === this.state.pathname}
onClick={
this.props.isMobile
? () => {
......@@ -200,13 +206,17 @@ export default class SiderMenu extends PureComponent {
return ItemDom;
};
isMainMenu = key => {
return this.props.menuData.some(item => key && (item.key === key || item.path === key));
return this.props.menuData.some(item => {
if (key) {
return item.key === key || item.path === key;
}
return false;
});
};
handleOpenChange = openKeys => {
const lastOpenKey = openKeys[openKeys.length - 1];
const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1;
this.setState({
openKeys: moreThanOne ? [lastOpenKey] : [...openKeys],
openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys],
});
};
render() {
......
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