Last active
June 4, 2018 00:56
-
-
Save c4milo/da50016b6a6a6782d1b3 to your computer and use it in GitHub Desktop.
Simple breadcrumb Ember 2 component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: '', // Does not let Ember inject HTML into the component. | |
routing: Ember.inject.service('-routing'), | |
breadcrumbs: Ember.computed('routing.currentRouteName', function () { | |
let routeName = this.get('routing.currentRouteName'); | |
let routeNames = routeName.split('.'); | |
let len = routeNames.length; | |
let last = routeNames[len - 1]; | |
if (last === 'index' && len > 1) { | |
routeNames.pop(); | |
len--; | |
} | |
let routes = []; | |
let container = Ember.getOwner(this); | |
let name = ''; | |
for (let i = 0; i < len; i++) { | |
// if name is not empty then it means we are dealing with a nested route. So | |
// we need to lookup the entire name. | |
if (name != '') { | |
name += '.' + routeNames[i]; | |
} else { | |
name = routeNames[i]; | |
} | |
let route = container.lookup(`route:${name}`); | |
if (!route || !route.label) { | |
console.warn(`hooklift-breadcrumb: route label for "${name}" pod was not found. Skipping.`); | |
continue; | |
} | |
routes.push({ name: name, label: route.label }); | |
} | |
return routes; | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
label: 'Metrics', | |
title: Ember.computed('label', function () { | |
return `Hooklift | ${this.get('label')}`; | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment