github.com/aminovpavel/nomad@v0.11.8/ui/app/services/breadcrumbs.js (about) 1 import { getOwner } from '@ember/application'; 2 import Service, { inject as service } from '@ember/service'; 3 import { computed } from '@ember/object'; 4 5 export default Service.extend({ 6 router: service(), 7 8 // currentURL is only used to listen to all transitions. 9 // currentRouteName has all information necessary to compute breadcrumbs, 10 // but it doesn't change when a transition to the same route with a different 11 // model occurs. 12 breadcrumbs: computed('router.currentURL', 'router.currentRouteName', function() { 13 const owner = getOwner(this); 14 const allRoutes = (this.get('router.currentRouteName') || '') 15 .split('.') 16 .without('') 17 .map((segment, index, allSegments) => allSegments.slice(0, index + 1).join('.')); 18 19 let crumbs = []; 20 allRoutes.forEach(routeName => { 21 const route = owner.lookup(`route:${routeName}`); 22 23 // Routes can reset the breadcrumb trail to start anew even 24 // if the route is deeply nested. 25 if (route.resetBreadcrumbs) { 26 crumbs = []; 27 } 28 29 // Breadcrumbs are either an array of static crumbs 30 // or a function that returns breadcrumbs given the current 31 // model for the route's controller. 32 let breadcrumbs = route.breadcrumbs || []; 33 if (typeof breadcrumbs === 'function') { 34 breadcrumbs = breadcrumbs(route.get('controller.model')) || []; 35 } 36 37 crumbs.push(...breadcrumbs); 38 }); 39 40 return crumbs; 41 }), 42 });