I need to get the current route name in my ember application; I tried this: Ember App.Router.router.currentState undefined but it doesn't work for me (there is probablig something i'm missimg...) I use Ember rc6 and I have a multilingual app; in the applicationRoute I detect the browser's language and I redirect to the correct page with:
this.transitionTo(userLang);
but I would like this to be executed only when user are on the home page, so something like this:
if (currentRoute == 'home'){
this.transitionTo(userLang)
}
Currently as of Ember 1.7.0 you can get the current route from within a route by calling
this.routeName
.If you want to get current route in your component or controller you can inject routing service (
routing: Ember.inject.service('-routing')
)(for more) and use:
this.get('routing.currentRouteName')
orthis.get('routing.currentPath')
Example with component and computed property:
Example with controller and computed property:
Current route in your route you just need
this.routeName
Example with route:
You could observe the
application
'scurrentPath
and set it to the current route accordingly when it changes:This way you have access to the
currentPath
when ever you want withApp.get('currentPath');
E.g.
Hope it helps.