|
|
@@ -1,13 +1,20 @@
|
|
|
import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
+import urljoin from 'url-join';
|
|
|
+
|
|
|
import LinkedPagePath from '../../models/LinkedPagePath';
|
|
|
|
|
|
|
|
|
const PagePathHierarchicalLink = (props) => {
|
|
|
- const { linkedPagePath } = props;
|
|
|
+ const { linkedPagePath, basePath } = props;
|
|
|
|
|
|
+ // render root element
|
|
|
if (linkedPagePath.isRoot) {
|
|
|
+ if (basePath != null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
return props.isPageInTrash
|
|
|
? (
|
|
|
<>
|
|
|
@@ -31,25 +38,29 @@ const PagePathHierarchicalLink = (props) => {
|
|
|
|
|
|
const isParentExists = linkedPagePath.parent != null;
|
|
|
const isParentRoot = isParentExists && linkedPagePath.parent.isRoot;
|
|
|
+ const isSeparatorRequired = isParentExists && !isParentRoot;
|
|
|
+
|
|
|
+ const href = encodeURI(urljoin(basePath || '', linkedPagePath.href));
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
{ isParentExists && (
|
|
|
- <>
|
|
|
- <PagePathHierarchicalLink linkedPagePath={linkedPagePath.parent} />
|
|
|
- { !isParentRoot && (
|
|
|
- <span className="separator">/</span>
|
|
|
- ) }
|
|
|
- </>
|
|
|
+ <PagePathHierarchicalLink linkedPagePath={linkedPagePath.parent} basePath={basePath} />
|
|
|
+ ) }
|
|
|
+ { isSeparatorRequired && (
|
|
|
+ <span className="separator">/</span>
|
|
|
) }
|
|
|
|
|
|
- <a className="page-segment" href={encodeURI(linkedPagePath.href)}>{linkedPagePath.pathName}</a>
|
|
|
+ <a className="page-segment" href={href}>{linkedPagePath.pathName}</a>
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
PagePathHierarchicalLink.propTypes = {
|
|
|
linkedPagePath: PropTypes.instanceOf(LinkedPagePath).isRequired,
|
|
|
- isPageInTrash: PropTypes.bool,
|
|
|
+ basePath: PropTypes.string,
|
|
|
+
|
|
|
+ isPageInTrash: PropTypes.bool, // TODO: omit
|
|
|
};
|
|
|
|
|
|
export default PagePathHierarchicalLink;
|