Ember.js gets the current route

I am switching to the new ember router, but I have a very simple question - how can I determine which route I am on now? Before you can do something like App.router.get('currentState') , but that no longer works, as the router no longer inherits from StateManager

+6
source share
3 answers

Look at the question .

Summary: currentState now stored in the currentPath property in your ApplicationController. The decision made was to observe this property, to write it to a global property:

 App = Em.Application.create({ currentPath: '' }); ApplicationController : Ember.Controller.extend({ updateCurrentPath: function() { App.set('currentPath', this.get('currentPath')); }.observes('currentPath') }); 
+8
source

I will probably be blown up for this, but after a ton of disappointment with this, I decided to implement a really ugly workaround.

My use case was trying to get the id of the current message because I sent him a response. Think of something like this for our current route:

"... # / entry / 12345"

my workaround (the ugliest code):

 var currentId = window.location.hash.split('/')[2]; App.Message.createRecord({ content: message, inReplyTo: currentId }).get('transaction').commit(); 
+6
source

In the controller, I can get the current route name using the code below. Good luck.

this.get ("currentRouteName")

+1
source

All Articles