diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 930ffdb3d4adafc7bb0446113def6286a1b591a5..29a4346f4de80cc03d7c31beb5a9b984060e897d 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -6,6 +6,7 @@ import { connect } from 'dva'; import { Route, Redirect, Switch, routerRedux } from 'dva/router'; import { ContainerQuery } from 'react-container-query'; import classNames from 'classnames'; +import pathToRegexp from 'path-to-regexp'; import { enquireScreen, unenquireScreen } from 'enquire-js'; import GlobalHeader from '../components/GlobalHeader'; import GlobalFooter from '../components/GlobalFooter'; @@ -108,15 +109,22 @@ class BasicLayout extends React.PureComponent { type: 'user/fetchCurrent', }); } - componentWillUnmount(){ + componentWillUnmount() { unenquireScreen(this.enquireHandler); } getPageTitle() { const { routerData, location } = this.props; const { pathname } = location; let title = 'Ant Design Pro'; - if (routerData[pathname] && routerData[pathname].name) { - title = `${routerData[pathname].name} - Ant Design Pro`; + let currRouterData = null; + // match params path + Object.keys(routerData).forEach(key => { + if (pathToRegexp(key).test(pathname)) { + currRouterData = routerData[key]; + } + }); + if (currRouterData && currRouterData.name) { + title = `${currRouterData.name} - Ant Design Pro`; } return title; }