Commit c1c36b61 authored by jim's avatar jim

Fix menu click exception

parent 2c0e700f
...@@ -2,9 +2,7 @@ const path = require('path'); ...@@ -2,9 +2,7 @@ const path = require('path');
export default { export default {
entry: 'src/index.js', entry: 'src/index.js',
extraBabelPlugins: [ extraBabelPlugins: [['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]],
['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
],
env: { env: {
development: { development: {
extraBabelPlugins: ['dva-hmr'], extraBabelPlugins: ['dva-hmr'],
...@@ -19,5 +17,6 @@ export default { ...@@ -19,5 +17,6 @@ export default {
template: './src/index.ejs', template: './src/index.ejs',
}, },
publicPath: '/', publicPath: '/',
disableDynamicImport: true,
hash: true, hash: true,
}; };
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
"path-to-regexp": "^2.1.0", "path-to-regexp": "^2.1.0",
"prop-types": "^15.5.10", "prop-types": "^15.5.10",
"qs": "^6.5.0", "qs": "^6.5.0",
"rc-drawer-menu": "^0.5.0", "rc-drawer-menu": "^1.1.0",
"react": "^16.3.1", "react": "^16.3.1",
"react-container-query": "^0.11.0", "react-container-query": "^0.11.0",
"react-document-title": "^2.0.3", "react-document-title": "^2.0.3",
...@@ -51,14 +51,14 @@ ...@@ -51,14 +51,14 @@
"devDependencies": { "devDependencies": {
"@types/react": "^16.3.8", "@types/react": "^16.3.8",
"@types/react-dom": "^16.0.5", "@types/react-dom": "^16.0.5",
"antd-theme-webpack-plugin": "^1.0.8",
"babel-eslint": "^8.1.2", "babel-eslint": "^8.1.2",
"babel-plugin-dva-hmr": "^0.4.1", "babel-plugin-dva-hmr": "^0.4.1",
"babel-plugin-import": "^1.6.7", "babel-plugin-import": "^1.6.7",
"babel-plugin-module-resolver": "^3.1.1", "babel-plugin-module-resolver": "^3.1.1",
"cross-env": "^5.1.1",
"antd-theme-webpack-plugin": "^1.0.8",
"babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-runtime": "^6.9.2", "babel-runtime": "^6.9.2",
"cross-env": "^5.1.1",
"cross-port-killer": "^1.0.1", "cross-port-killer": "^1.0.1",
"enzyme": "^3.1.0", "enzyme": "^3.1.0",
"eslint": "^4.14.0", "eslint": "^4.14.0",
...@@ -74,13 +74,13 @@ ...@@ -74,13 +74,13 @@
"husky": "^0.14.3", "husky": "^0.14.3",
"lint-staged": "^7.0.5", "lint-staged": "^7.0.5",
"mockjs": "^1.0.1-beta3", "mockjs": "^1.0.1-beta3",
"prettier": "1.12.1", "prettier": "1.13.2",
"pro-download": "^1.0.1", "pro-download": "^1.0.1",
"redbox-react": "^1.5.0", "redbox-react": "^1.5.0",
"regenerator-runtime": "^0.11.1", "regenerator-runtime": "^0.11.1",
"roadhog": "^2.4.1", "roadhog": "2.3.0",
"roadhog-api-doc": "^1.0.3", "roadhog-api-doc": "^1.0.3",
"stylelint": "^8.4.0", "stylelint": "^9.2.1",
"stylelint-config-prettier": "^3.0.4", "stylelint-config-prettier": "^3.0.4",
"stylelint-config-standard": "^18.0.0" "stylelint-config-standard": "^18.0.0"
}, },
......
...@@ -136,7 +136,7 @@ class Sidebar extends PureComponent { ...@@ -136,7 +136,7 @@ class Sidebar extends PureComponent {
<DrawerMenu <DrawerMenu
parent={null} parent={null}
level={null} level={null}
iconChild={null} handleChild={null}
open={collapse} open={collapse}
placement="right" placement="right"
width="336px" width="336px"
......
...@@ -65,16 +65,22 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) => ...@@ -65,16 +65,22 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) =>
); );
export default class SiderMenu extends PureComponent { export default class SiderMenu extends PureComponent {
static getDerivedStateFromProps(nextProps) { static getDerivedStateFromProps(props, state) {
return { const { pathname } = state;
openKeys: getDefaultCollapsedSubMenus(nextProps), if (props.location.pathname !== pathname) {
}; return {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props),
};
}
return null;
} }
constructor(props) { constructor(props) {
super(props); super(props);
this.menus = props.menuData; this.menus = props.menuData;
this.flatMenuKeys = getFlatMenuKeys(props.menuData); this.flatMenuKeys = getFlatMenuKeys(props.menuData);
this.state = { this.state = {
pathname: props.location.pathname,
openKeys: getDefaultCollapsedSubMenus(props), openKeys: getDefaultCollapsedSubMenus(props),
}; };
} }
...@@ -113,7 +119,7 @@ export default class SiderMenu extends PureComponent { ...@@ -113,7 +119,7 @@ export default class SiderMenu extends PureComponent {
<Link <Link
to={itemPath} to={itemPath}
target={target} target={target}
replace={itemPath === this.props.location.pathname} replace={itemPath === this.state.pathname}
onClick={ onClick={
this.props.isMobile this.props.isMobile
? () => { ? () => {
...@@ -200,13 +206,17 @@ export default class SiderMenu extends PureComponent { ...@@ -200,13 +206,17 @@ export default class SiderMenu extends PureComponent {
return ItemDom; return ItemDom;
}; };
isMainMenu = key => { 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 => { handleOpenChange = openKeys => {
const lastOpenKey = openKeys[openKeys.length - 1];
const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1; const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1;
this.setState({ this.setState({
openKeys: moreThanOne ? [lastOpenKey] : [...openKeys], openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys],
}); });
}; };
render() { 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