chrmod
chrmod

Reputation: 1445

How to get current routeName?

Assuming my application in bound to window.App: I can get it's router with App.__container__.lookup("router:main").

How can I access current route? Specifically I want to get its property routeName.

Upvotes: 2

Views: 3343

Answers (1)

intuitivepixel
intuitivepixel

Reputation: 23322

It exist a property called currentPath which is a computed alias for the current state of the application. To get the current routeName which is the same thing 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 with:

App.get('currentPath');

See here for more info for the currentPath property.

Also worth mentioning is that you can enable the flag LOG_TRANSITIONS to true to have the current route name 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") only for debugging purposes since it's an internal API.

Hope it helps.

Upvotes: 10

Related Questions