Determining the current path in Ember.js

Do you want to know the current path in your Ember.js app? This was asked on Stack Overflow recently and I thought it was a neat trick.

App = Ember,Application.create({
currentPath: ''
});
ApplicationController : Ember.Controller.extend({
currentPathDidChange: function() {
App.set('currentPath', this.get('currentPath'));
}.observes('currentPath')
});
view raw gistfile1.txt hosted with ❤ by GitHub

Now you can access your current path from anywhere with:

App.get('currentPath');
view raw gistfile1.txt hosted with ❤ by GitHub
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a comment