From a5907a306f5f09bed82fbe9906da0c161530a616 Mon Sep 17 00:00:00 2001 From: jim Date: Wed, 2 May 2018 11:19:53 +0800 Subject: [PATCH] fix #1248 match params path --- src/layouts/BasicLayout.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 930ffdb3..29a4346f 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; } -- GitLab