Add breadcrumb navigation
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
import Component from '@ember/component';
|
||||
|
||||
export default Component.extend({
|
||||
});
|
||||
32
app/components/breadcrumb-nav/component.js
Normal file
32
app/components/breadcrumb-nav/component.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import Component from '@ember/component';
|
||||
import EmberObject from '@ember/object';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
|
||||
export default Component.extend({
|
||||
|
||||
tagName: 'nav',
|
||||
classNames: ['breadcrumb-nav'],
|
||||
|
||||
currentDirPath: null,
|
||||
|
||||
linkItems: function() {
|
||||
let currentDirPath = this.get('currentDirPath');
|
||||
if (isEmpty(currentDirPath)) { return []; }
|
||||
let linkItems = [];
|
||||
|
||||
let dirs = currentDirPath.split('/')
|
||||
.reject(i => isEmpty(i));
|
||||
|
||||
dirs.forEach(dirname => {
|
||||
let path = currentDirPath.match(`(.*${dirname})/`)[0];
|
||||
|
||||
linkItems.pushObject(EmberObject.create({
|
||||
name: dirname,
|
||||
path: path
|
||||
}));
|
||||
});
|
||||
|
||||
return linkItems;
|
||||
}.property('currentDirPath')
|
||||
|
||||
});
|
||||
4
app/components/breadcrumb-nav/template.hbs
Normal file
4
app/components/breadcrumb-nav/template.hbs
Normal file
@@ -0,0 +1,4 @@
|
||||
<span class="node">{{#link-to "index" (query-params path='/')}}Home{{/link-to}}</span>
|
||||
{{#each linkItems as |item|}}
|
||||
<span class="node">{{#link-to "index" (query-params path=item.path)}}{{item.name}}{{/link-to}}</span>
|
||||
{{/each}}
|
||||
Reference in New Issue
Block a user