diff --git a/src/components/SiderMenu/BaseMenu.js b/src/components/SiderMenu/BaseMenu.js index 0fc635dea583d1913c58750945b033a108a110da..427469bd2c0113e03a9b32e8659f6be20f17b67c 100644 --- a/src/components/SiderMenu/BaseMenu.js +++ b/src/components/SiderMenu/BaseMenu.js @@ -3,7 +3,6 @@ import { Menu, Icon } from 'antd'; import Link from 'umi/link'; import isEqual from 'lodash/isEqual'; import memoizeOne from 'memoize-one'; -import { formatMessage } from 'umi/locale'; import pathToRegexp from 'path-to-regexp'; import { urlToList } from '../_utils/pathTools'; import styles from './index.less'; @@ -83,7 +82,7 @@ export default class BaseMenu extends PureComponent { getSubMenuOrItem = item => { // doc: add hideChildrenInMenu if (item.children && !item.hideChildrenInMenu && item.children.some(child => child.name)) { - const name = item.locale ? formatMessage({ id: item.locale }) : item.name; + const { name } = item; return ( { - const name = item.locale ? formatMessage({ id: item.locale }) : item.name; + const { name } = item; const itemPath = this.conversionPath(item.path); const icon = getIcon(item.icon); const { target } = item; diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index aa29acc7cd2b7c74fe8348f53b4686cf89d96f60..81b2ce88209b3a0bacedc5e2e9ff4a59c7ae9b2a 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -24,30 +24,30 @@ const { Content } = Layout; function formatter(data, parentAuthority, parentName) { return data .map(item => { + if (!item.name || !item.path) { + return null; + } + let locale = 'menu'; - if (parentName && item.name) { + if (parentName) { locale = `${parentName}.${item.name}`; - } else if (item.name) { + } else { locale = `menu.${item.name}`; - } else if (parentName) { - locale = parentName; - } - if (item.path) { - const result = { - ...item, - locale, - authority: item.authority || parentAuthority, - }; - if (item.routes) { - const children = formatter(item.routes, item.authority, locale); - // Reduce memory usage - result.children = children; - } - delete result.routes; - return result; } - return null; + const result = { + ...item, + name: formatMessage({ id: locale, defaultMessage: item.name }), + locale, + authority: item.authority || parentAuthority, + }; + if (item.routes) { + const children = formatter(item.routes, item.authority, locale); + // Reduce memory usage + result.children = children; + } + delete result.routes; + return result; }) .filter(item => item); }