From 1f4b5bbf5d80e9b6986b545ea23162373a011bfe Mon Sep 17 00:00:00 2001 From: Amumu Date: Tue, 14 Aug 2018 16:29:55 +0800 Subject: [PATCH] Break the loop and avoid being overwritten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首次匹配终止循环,提高性能并避免被二次匹配覆盖 --- src/layouts/BasicLayout.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 4fcdac68..e1a3363f 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -134,10 +134,12 @@ export default class BasicLayout extends React.PureComponent { let title = 'Ant Design Pro'; let currRouterData = null; // match params path - Object.keys(routerData).forEach(key => { + Object.keys(routerData).some(key => { if (pathToRegexp(key).test(pathname)) { currRouterData = routerData[key]; + return true; } + return false; }); if (currRouterData && currRouterData.name) { title = `${currRouterData.name} - Ant Design Pro`; -- GitLab