diff --git a/src/dashboard/lambda/mock/matchMock.js b/src/dashboard/lambda/mock/matchMock.js index d74236126..e8db02eb0 100644 --- a/src/dashboard/lambda/mock/matchMock.js +++ b/src/dashboard/lambda/mock/matchMock.js @@ -1,4 +1,4 @@ -const pathToRegexp = require('path-to-regexp'); +const { pathToRegexp } = require('path-to-regexp'); const bodyParser = require('body-parser'); const mockFile = require('./index'); @@ -47,11 +47,11 @@ function normalizeConfig(config) { const handler = config[key]; const { method, path } = parseKey(key); const keys = []; - const re = pathToRegexp(path, keys); + const { regexp } = pathToRegexp(path, keys); memo.push({ method, path, - re, + regexp, keys, handler: createHandler(method, path, handler), }); @@ -83,9 +83,9 @@ function matchMock(req) { } // eslint-disable-next-line no-restricted-syntax for (const mock of mockData) { - const { method, re, keys } = mock; + const { method, regexp, keys } = mock; if (method === exceptMethod) { - const match = re.exec(req.path); + const match = regexp.exec(req.path); if (match) { const params = {}; @@ -104,7 +104,7 @@ function matchMock(req) { } } - return mockData.filter(({ method, re }) => method === exceptMethod && re.test(exceptPath))[0]; + return mockData.filter(({ method, regexp }) => method === exceptMethod && regexp.test(exceptPath))[0]; } module.exports = (req, res, next) => { const match = matchMock(req); diff --git a/src/dashboard/package.json b/src/dashboard/package.json index 26d22ada9..071854fdc 100644 --- a/src/dashboard/package.json +++ b/src/dashboard/package.json @@ -71,7 +71,7 @@ "numeral": "^2.0.6", "nzh": "^1.0.4", "omit.js": "^1.0.0", - "path-to-regexp": "^8.1.0", + "path-to-regexp": "^8.2.0", "prop-types": "^15.6.2", "qs": "^6.6.0", "rc-animate": "^2.6.0", diff --git a/src/dashboard/src/components/PageHeaderWrapper/breadcrumb.js b/src/dashboard/src/components/PageHeaderWrapper/breadcrumb.js index 3685759d1..d704d21f5 100644 --- a/src/dashboard/src/components/PageHeaderWrapper/breadcrumb.js +++ b/src/dashboard/src/components/PageHeaderWrapper/breadcrumb.js @@ -1,5 +1,5 @@ import React from 'react'; -import pathToRegexp from 'path-to-regexp'; +import { pathToRegexp } from 'path-to-regexp'; import { Link, formatMessage } from 'umi'; import { urlToList } from '../_utils/pathTools'; import { menu } from '../../defaultSettings'; @@ -33,7 +33,8 @@ export const getBreadcrumb = (breadcrumbNameMap, url) => { let breadcrumb = breadcrumbNameMap[url]; if (!breadcrumb) { Object.keys(breadcrumbNameMap).forEach(item => { - if (pathToRegexp(item).test(url)) { + const { regexp } = pathToRegexp(item); + if (regexp.test(url)) { breadcrumb = breadcrumbNameMap[item]; } }); diff --git a/src/dashboard/src/components/SiderMenu/SiderMenuUtils.js b/src/dashboard/src/components/SiderMenu/SiderMenuUtils.js index 6e04ec134..9353d135f 100644 --- a/src/dashboard/src/components/SiderMenu/SiderMenuUtils.js +++ b/src/dashboard/src/components/SiderMenu/SiderMenuUtils.js @@ -1,4 +1,4 @@ -import pathToRegexp from 'path-to-regexp'; +import { pathToRegexp } from 'path-to-regexp'; import { urlToList } from '../_utils/pathTools'; /** @@ -20,7 +20,8 @@ export const getFlatMenuKeys = menuData => { export const getMenuMatches = (flatMenuKeys, path) => flatMenuKeys.filter(item => { if (item) { - return pathToRegexp(item).test(path); + const { regexp } = pathToRegexp(item); + return regexp.test(path); } return false; }); diff --git a/src/dashboard/src/pages/Authorized.js b/src/dashboard/src/pages/Authorized.js index c6b85c1a7..bfa747a73 100644 --- a/src/dashboard/src/pages/Authorized.js +++ b/src/dashboard/src/pages/Authorized.js @@ -1,5 +1,5 @@ import React from 'react'; -import pathToRegexp from 'path-to-regexp'; +import { pathToRegexp } from 'path-to-regexp'; import { connect, Redirect } from 'umi'; import Authorized from '@/utils/Authorized'; import { getAuthority } from '@/utils/authority'; @@ -12,7 +12,8 @@ function AuthComponent({ children, location, routerData }) { let authorities; routeData.forEach(route => { // match prefix - if (pathToRegexp(`${route.path}(.*)`).test(path)) { + const { regexp } = pathToRegexp(`${route.path}(.*)`); + if (regexp.test(path)) { authorities = route.authority || authorities; // get children authority recursively diff --git a/src/dashboard/src/utils/getPageTitle.js b/src/dashboard/src/utils/getPageTitle.js index 7e507d00d..0192c734e 100644 --- a/src/dashboard/src/utils/getPageTitle.js +++ b/src/dashboard/src/utils/getPageTitle.js @@ -1,11 +1,15 @@ import { formatMessage } from 'umi'; -import pathToRegexp from 'path-to-regexp'; +import { pathToRegexp } from 'path-to-regexp'; import isEqual from 'lodash/isEqual'; import memoizeOne from 'memoize-one'; import { menu, title } from '../defaultSettings'; export const matchParamsPath = (pathname, breadcrumbNameMap) => { - const pathKey = Object.keys(breadcrumbNameMap).find(key => pathToRegexp(key).test(pathname)); + const pathKey = Object.keys(breadcrumbNameMap).find(key => { + const { regexp } = pathToRegexp(key); + return regexp.test(pathname); + }); + return breadcrumbNameMap[pathKey]; };