Skip to content

Instantly share code, notes, and snippets.

@xcambar
Created September 3, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcambar/7d2d116519c68eb54868 to your computer and use it in GitHub Desktop.
Save xcambar/7d2d116519c68eb54868 to your computer and use it in GitHub Desktop.
Let the outside world know that your Ember app has successfully transitioned from a route to another
/*
* For the sake of simplicity,
* Let's assume that your app is globally regostered as `MyApp`
*/
// Prepare your app to trigger the `transitioned` event
MyApp.reopen(Ember.Evented);
MyApp.__container__.lookup('controller:application').addObserver('currentPath', function () {
var _path = this.get('currentPath');
if (_path.indexOf('loading') !== -1) { return; }
if (_path.indexOf('error') !== -1) { return; }
Ember.run.scheduleOnce(
'afterRender',
this,
MyApp.trigger.bind(MyApp, 'transitioned', _path));
});
//Register a listener
MyApp.on('transitioned', function (path) {
console.log('Transitioned to', path);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment