@armikhalev wrote:
What would be the best way to implement additional names to routes in the router to get them in components?
What it might look like:
Router.map(function() { this.route('about', {title:'About us', path:'/about'}); this.route('first', {title:'First Page', path:'first-page'}); this.route('second', {title:'Second awesome page', path:'second-page'}); });
Then in component I would like to get it in a similar to the following way:
export default Ember.Component.extend({ routing: Ember.inject.service('-routing'), title: Ember.computed('routing.currentRoute.title', function() { let routeTitle = this.get('routing.currentRoute.title'); return routeTitle; }) });
What I tried but feel it is not the best way at all, I get currentRoute with "routing.currentRouteName" and then conditionally return needed title, similar to this:
let routes = { "about": "About us", "first-page": "First Page", "second-page": "Second Awesome Page" } let routeTitle = this.get('routing.currentRouteName'); return routes[routeName];
I'm thinking it is also possible to use observables but I would like to see the right way of doing this in Ember.
Posts: 4
Participants: 2