-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
38 lines (30 loc) · 1.1 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* eslint-disable import/no-dynamic-require */
import React from 'react';
// eslint-disable-next-line no-undef
const PageRenderer = require(__COMPONENT_BASE_PATH__).default;
const buildPageElement = (match, prevProps, props) => {
const usePageRenderer = match && !prevProps;
const pageElementProps = match && prevProps && props ? prevProps : props;
const { component, page } = pageElementProps.pageResources || {};
const { element: fallbackComponent } = props;
if (usePageRenderer) {
return React.createElement(PageRenderer, { match, key: match.route.path });
}
if (component) {
return React.createElement(component.default || component, {
...pageElementProps,
key: page.path,
});
}
return fallbackComponent;
};
const buildModalElement = (match, pageResources, props) => {
if (!match) return null;
if (pageResources) {
const { component } = pageResources;
const { path } = pageResources.page;
return React.createElement(component.default || component, { ...props, key: path });
}
return props.element;
};
export { buildPageElement, buildModalElement };