eltiare
eltiare

Reputation: 1939

EmberJS transitionTo / linkTo callbacks

I'd like to have a callback that is fired every time that a link is followed or a transitionTo is called in EmberJS. The reason I want to do this is to hide menus/dropdowns that might be open when the transition is made. I haven't the foggiest idea of where to start with this. My Google-fu might be weak so apologies if this is a silly question.

Upvotes: 2

Views: 427

Answers (1)

intuitivepixel
intuitivepixel

Reputation: 23322

All transitions types, URL changes and transitionTo will fire a willTransition event on the currently active route. This gives the active routes a chance to be informed when it happens.

App.FooRoute = Ember.Route.extend({
  events: {
    willTransition: function(transition) {
      // hide here your menus
    }
  }
});

If you want this to happen on every transition you could extend the default Ember.Route class with this behaviour:

Ember.Route.reopen({
  events: {
    willTransition: function(transition) {
      // hide here your menus
    }
  }
});

Hope it helps.

Upvotes: 4

Related Questions