Route#willTransition event

willTransition (transition) public

Defined in packages/ember-routing/lib/system/route.js:547

The willTransition action is fired at the beginning of any attempted transition with a Transition object as the sole argument. This action can be used for aborting, redirecting, or decorating the transition from the currently active routes.

A good example is preventing navigation when a form is half-filled out:

App.ContactFormRoute = Ember.Route.extend({
  actions: {
    willTransition: function(transition) {
      if (this.controller.get('userHasEnteredData')) {
        this.controller.displayNavigationConfirm();
        transition.abort();
      }
    }
  }
});

You can also redirect elsewhere by calling this.transitionTo('elsewhere') from within willTransition. Note that willTransition will not be fired for the redirecting transitionTo, since willTransition doesn't fire when there is already a transition underway. If you want subsequent willTransition actions to fire for the redirecting transition, you must first explicitly call transition.abort().

To allow the willTransition event to continue bubbling to the parent route, use return true;. When the willTransition method has a return value of true then the parent route's willTransition method will be fired, enabling "bubbling" behavior for the event.

Parameters:

transition Transition
doc_EmberJs
2016-11-30 16:53:15
Comments
Leave a Comment

Please login to continue.