How do I get the current route name?
There is a property currentPath
in it that is a computed alias for the current state of the application. To get the current one routeName
, it is the same as you could do something like this:
App = Ember,Application.create({
currentPath: ''
});
ApplicationController : Ember.Controller.extend({
currentPathDidChange: function() {
App.set('currentPath', this.get('currentPath'));
}.observes('currentPath')
});
and then access it from anywhere:
App.get('currentPath');
For details on properties currentPath
see here .
It's also worth mentioning that you can enable the flag LOG_TRANSITIONS
to true so that the name of the current route is logged in your browser console every time the application changes state / route:
App = Ember.Application.create({ LOG_TRANSITION: true });
Note
Use this App.__container__.lookup("router:main")
for debugging purposes only as it is an internal API.
Hope it helps.
source to share