diff --git a/package.json b/package.json index 6505ae9..62184ae 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "jsonp": "^0.2.1", "less-vars-to-js": "^1.1.2", "mockjs": "^1.0.1-beta3", + "path-to-regexp": "^1.7.0", "rc-tween-one": "^1.0.0", "redbox-react": "^1.2.10" }, diff --git a/src/components/Layout/Bread.js b/src/components/Layout/Bread.js index 25422ae..43003a7 100644 --- a/src/components/Layout/Bread.js +++ b/src/components/Layout/Bread.js @@ -3,46 +3,43 @@ import PropTypes from 'prop-types' import { Breadcrumb, Icon } from 'antd' import { Link } from 'dva/router' import styles from './Bread.less' -import { menu } from '../../utils' +import pathToRegexp from 'path-to-regexp' +import { queryArray } from '../../utils' -let pathSet = [] -const getPathSet = function (menuArray, parentPath) { - parentPath = parentPath || '/' - menuArray.forEach(item => { - pathSet[(parentPath + item.key).replace(/\//g, '-').hyphenToHump()] = { - path: parentPath + item.key, - name: item.name, - icon: item.icon || '', - clickable: item.clickable === undefined, +const Bread = ({ location, menu }) => { + // 匹配当前路由 + let pathArray = [] + let current + for (let index in menu) { + if (menu[index].router && pathToRegexp(menu[index].router).exec(location.pathname)) { + current = menu[index] + break } - if (item.child) { - getPathSet(item.child, `${parentPath}${item.key}/`) - } - }) -} -getPathSet(menu) + } -function Bread ({ location }) { - let pathNames = [] - location.pathname.substr(1).split('/').forEach((item, key) => { - if (key > 0) { - pathNames.push((`${pathNames[key - 1]}-${item}`).hyphenToHump()) - } else { - pathNames.push((`-${item}`).hyphenToHump()) - } - }) + if (!current) { + return (