1 | import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2 | import pathToRegexp from 'path-to-regexp';
|
3 | export var matchParamsPath = function matchParamsPath(pathname, breadcrumb, breadcrumbMap) {
|
4 |
|
5 |
|
6 | if (breadcrumbMap) {
|
7 | var pathKey = _toConsumableArray(breadcrumbMap.keys()).find(function (key) {
|
8 | return pathToRegexp(key).test(pathname);
|
9 | });
|
10 |
|
11 | if (pathKey) {
|
12 | return breadcrumbMap.get(pathKey);
|
13 | }
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 | if (breadcrumb) {
|
19 | var _pathKey = Object.keys(breadcrumb).find(function (key) {
|
20 | return pathToRegexp(key).test(pathname);
|
21 | });
|
22 |
|
23 | if (_pathKey) {
|
24 | return breadcrumb[_pathKey];
|
25 | }
|
26 | }
|
27 |
|
28 | return {
|
29 | path: ''
|
30 | };
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | var getPageTitleInfo = function getPageTitleInfo(props, ignoreTitle) {
|
40 | var _props$pathname = props.pathname,
|
41 | pathname = _props$pathname === void 0 ? '/' : _props$pathname,
|
42 | breadcrumb = props.breadcrumb,
|
43 | breadcrumbMap = props.breadcrumbMap,
|
44 | formatMessage = props.formatMessage,
|
45 | title = props.title,
|
46 | _props$menu = props.menu,
|
47 | menu = _props$menu === void 0 ? {
|
48 | locale: false
|
49 | } : _props$menu;
|
50 | var pageTitle = ignoreTitle ? '' : title || '';
|
51 | var currRouterData = matchParamsPath(pathname, breadcrumb, breadcrumbMap);
|
52 |
|
53 | if (!currRouterData) {
|
54 | return {
|
55 | title: pageTitle,
|
56 | id: '',
|
57 | pageName: pageTitle
|
58 | };
|
59 | }
|
60 |
|
61 | var pageName = currRouterData.name;
|
62 |
|
63 | if (menu.locale !== false && currRouterData.locale && formatMessage) {
|
64 | pageName = formatMessage({
|
65 | id: currRouterData.locale || '',
|
66 | defaultMessage: currRouterData.name
|
67 | });
|
68 | }
|
69 |
|
70 | if (!pageName) {
|
71 | return {
|
72 | title: pageTitle,
|
73 | id: currRouterData.locale || '',
|
74 | pageName: pageTitle
|
75 | };
|
76 | }
|
77 |
|
78 | if (ignoreTitle || !title) {
|
79 | return {
|
80 | title: pageName,
|
81 | id: currRouterData.locale || '',
|
82 | pageName: pageName
|
83 | };
|
84 | }
|
85 |
|
86 | return {
|
87 | title: "".concat(pageName, " - ").concat(title),
|
88 | id: currRouterData.locale || '',
|
89 | pageName: pageName
|
90 | };
|
91 | };
|
92 |
|
93 | export { getPageTitleInfo };
|
94 |
|
95 | var getPageTitle = function getPageTitle(props, ignoreTitle) {
|
96 | return getPageTitleInfo(props, ignoreTitle).title;
|
97 | };
|
98 |
|
99 | export default getPageTitle; |
\ | No newline at end of file |