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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s