Reputation: 38613
In Ember 2.0 controller will be deprecated. How do I access the currentPath. At the moment I am doing the following.
needs: ["application"],
routeName : function() {
return this.get('controllers.application.currentPath');
}.property('controllers.application.currentPath),
Upvotes: 1
Views: 3575
Reputation: 2135
Taking the 3.9 API docs, here is how you would do it now. Using the public APIs is probably recommended (currentRouteName, currentURL), but super easy to refactor like so for now.
export default Service.extend({
router: service(),
whereAmI: computed('router.currentRouteName', function() {
return this.router._router.currentPath; // 'users.index'
})
});
https://api.emberjs.com/ember/3.9/classes/RouterService https://github.com/emberjs/ember.js/blob/v3.9.0/packages/%40ember/-internals/routing/lib/system/router.ts#L1631
Upvotes: 1
Reputation: 1120
You can do something like
applicationController: Ember.inject.controller("application"),
routeName : function() {
return this.get('applicationController.currentPath');
}.property('applicationController.currentPath)
Upvotes: 4
Reputation: 11293
If I recall correctly ember 1.8 added the routeName
property to route objects, you can access it from the route by calling this.routeName
(I am assuming that is what you want since your cp is named so).
On a side note you should start using the new computed property syntax:
routeName: Ember.computed('controllers.application.currentPath', function() {
return this.get('controllers.application.currentPath');
}),
Upvotes: 2