|
@@ -7,12 +7,21 @@ export default class PagePath extends React.Component {
|
|
|
|
|
|
|
|
this.state = {
|
|
this.state = {
|
|
|
pages: [],
|
|
pages: [],
|
|
|
|
|
+ isListPage: false,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
componentWillMount() {
|
|
|
|
|
+ // whether list page or not
|
|
|
|
|
+ const isListPage = this.props.pagePath.match(/\/$/);
|
|
|
|
|
+ this.setState({ isListPage });
|
|
|
|
|
+
|
|
|
|
|
+ // generate pages obj
|
|
|
let splitted = this.props.pagePath.split(/\//);
|
|
let splitted = this.props.pagePath.split(/\//);
|
|
|
splitted.shift(); // omit first element with shift()
|
|
splitted.shift(); // omit first element with shift()
|
|
|
|
|
+ if (splitted[splitted.length-1] === '') {
|
|
|
|
|
+ splitted.pop(); // omit last element with unshift()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
let pages = [];
|
|
let pages = [];
|
|
|
let parentPath = '/';
|
|
let parentPath = '/';
|
|
@@ -29,15 +38,19 @@ export default class PagePath extends React.Component {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const pageLength = this.state.pages.length;
|
|
const pageLength = this.state.pages.length;
|
|
|
|
|
+
|
|
|
const afterElements = [];
|
|
const afterElements = [];
|
|
|
this.state.pages.forEach((page, index) => {
|
|
this.state.pages.forEach((page, index) => {
|
|
|
|
|
+ const isLastElement = (index == pageLength-1);
|
|
|
|
|
+
|
|
|
|
|
+ // add elements
|
|
|
afterElements.push(
|
|
afterElements.push(
|
|
|
<span key={page.pagePath} className="path-segment">
|
|
<span key={page.pagePath} className="path-segment">
|
|
|
<a href={page.pagePath}>{page.pageName}</a>
|
|
<a href={page.pagePath}>{page.pageName}</a>
|
|
|
</span>);
|
|
</span>);
|
|
|
afterElements.push(
|
|
afterElements.push(
|
|
|
<span key={page.pagePath+'/'} className="separator">
|
|
<span key={page.pagePath+'/'} className="separator">
|
|
|
- <a href={page.pagePath+'/'} className={(index==pageLength-1) ? 'last-path' : ''}>/</a>
|
|
|
|
|
|
|
+ <a href={page.pagePath+'/'} className={(isLastElement && !this.state.isListPage) ? 'last-path' : ''}>/</a>
|
|
|
</span>
|
|
</span>
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|