Refactor some of the breadcrumb code
This commit is contained in:
parent
4898630a3e
commit
a585120d51
1 changed files with 10 additions and 17 deletions
|
@ -1,33 +1,26 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
let {
|
|
||||||
Breadcrumb,
|
|
||||||
BreadcrumbItem
|
|
||||||
} = require('react-bootstrap');
|
|
||||||
|
|
||||||
export default class Breadcrumbs extends React.Component {
|
export default class Breadcrumbs extends React.Component {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.urlParts = Object.freeze(location.pathname.split('/').slice(1, -1));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const parts = location.pathname.split('/').slice(1, -1);
|
|
||||||
var elements = [];
|
var elements = [];
|
||||||
for (var i = 0; i < parts.length; i++) {
|
for (var i = 0; i < this.urlParts.length; i++) {
|
||||||
var dirs = [];
|
var dirs = [];
|
||||||
for (var j = 0; j <= i; j++) {
|
for (var j = 0; j <= i; j++) {
|
||||||
dirs.push(parts[j]);
|
dirs.push(this.urlParts[j]);
|
||||||
}
|
}
|
||||||
if (i === (parts.length - 1)) {
|
if (i === (this.urlParts.length - 1)) {
|
||||||
elements.push(
|
elements.push(
|
||||||
<li className="active" href={url}>
|
<li className="active" href={url}>{this.urlParts[i]}</li>
|
||||||
{parts[i]}
|
|
||||||
</li>
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var url = '/' + dirs.join('/') + '/';
|
var url = '/' + dirs.join('/') + '/';
|
||||||
elements.push(
|
elements.push(
|
||||||
<li>
|
<li><a href={url}>{this.urlParts[i]}</a></li>
|
||||||
<a href={url}>
|
|
||||||
{parts[i]}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue