Skip to content

Commit

Permalink
pageTitleRender add pageName props
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jul 16, 2019
1 parent 90a2797 commit e759329
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/getPageTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,43 @@ export interface GetPageTitleProps {
breadcrumb?: { [path: string]: MenuDataItem };
menu?: Settings['menu'];
title?: Settings['title'];
formatMessage: (data: { id: any; defaultMessage?: string }) => string;
pageName?: string;
formatMessage?: (data: { id: any; defaultMessage?: string }) => string;
}

const getPageTitle = (props: GetPageTitleProps): string => {
const getPageTitle = (
props: GetPageTitleProps,
ignoreTile?: boolean,
): string => {
const {
pathname,
pathname = '/',
breadcrumb,
formatMessage,
title = 'Ant Design Pro',
menu = {
locale: false,
},
} = props;

const pageTitle = ignoreTile ? '' : title;
if (!pathname) {
return title;
return pageTitle;
}
const currRouterData = matchParamsPath(pathname, breadcrumb);
if (!currRouterData) {
return title;
return pageTitle;
}
let pageName = currRouterData.name;
if (menu.locale && currRouterData.locale) {
if (menu.locale && currRouterData.locale && formatMessage) {
pageName = formatMessage({
id: currRouterData.locale || '',
defaultMessage: currRouterData.name,
});
}

if (!pageName) {
return title;
return pageTitle;
}
if (ignoreTile) {
return pageName;
}
return `${pageName} - ${title}`;
};
Expand Down

0 comments on commit e759329

Please sign in to comment.