From 608d5998017ba6fc7337cb826e1211f8b30b81bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Fri, 14 Sep 2018 18:14:48 +0800 Subject: [PATCH] fix #2291 Increase authority judgment --- src/layouts/BasicLayout.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 3b59e48a..bf9cf4fe 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -16,6 +16,7 @@ import logo from '../assets/logo.svg'; import Footer from './Footer'; import Header from './Header'; import Context from './MenuContext'; +import Exception403 from '../pages/Exception/403'; const { Content } = Layout; @@ -76,6 +77,7 @@ class BasicLayout extends React.PureComponent { this.getPageTitle = memoizeOne(this.getPageTitle); this.getBreadcrumbNameMap = memoizeOne(this.getBreadcrumbNameMap, isEqual); this.breadcrumbNameMap = this.getBreadcrumbNameMap(); + this.matchParamsPath = memoizeOne(this.matchParamsPath, isEqual); } state = { @@ -156,14 +158,16 @@ class BasicLayout extends React.PureComponent { return routerMap; } + matchParamsPath = pathname => { + const pathKey = Object.keys(this.breadcrumbNameMap).find(key => + pathToRegexp(key).test(pathname) + ); + return this.breadcrumbNameMap[pathKey]; + }; + getPageTitle = pathname => { - let currRouterData = null; - // match params path - Object.keys(this.breadcrumbNameMap).forEach(key => { - if (pathToRegexp(key).test(pathname)) { - currRouterData = this.breadcrumbNameMap[key]; - } - }); + const currRouterData = this.matchParamsPath(pathname); + if (!currRouterData) { return 'Ant Design Pro'; } @@ -221,6 +225,7 @@ class BasicLayout extends React.PureComponent { const { isMobile } = this.state; const isTop = PropsLayout === 'topmenu'; const menuData = this.getMenuData(); + const routerConfig = this.matchParamsPath(pathname); const layout = ( {isTop && !isMobile ? null : ( @@ -247,12 +252,15 @@ class BasicLayout extends React.PureComponent { isMobile={isMobile} {...this.props} /> - {children} + + }> + {children} + +