Browse Source
* Added document title to UserLayout by identifying the current route object and using its name kaey to set the title * Adjusment to document title * feat: use same getPageTile functionpull/3578/head
committed by
GitHub
10 changed files with 98 additions and 60 deletions
@ -0,0 +1,26 @@ |
|||
import { formatMessage } from 'umi/locale'; |
|||
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)); |
|||
return breadcrumbNameMap[pathKey]; |
|||
}; |
|||
const getPageTitle = (pathname, breadcrumbNameMap) => { |
|||
const currRouterData = matchParamsPath(pathname, breadcrumbNameMap); |
|||
if (!currRouterData) { |
|||
return title; |
|||
} |
|||
const pageName = menu.disableLocal |
|||
? currRouterData.name |
|||
: formatMessage({ |
|||
id: currRouterData.locale || currRouterData.name, |
|||
defaultMessage: currRouterData.name, |
|||
}); |
|||
|
|||
return `${pageName} - ${title}`; |
|||
}; |
|||
|
|||
export default memoizeOne(getPageTitle, isEqual); |
|||
Loading…
Reference in new issue