0
votes

In certain circumstances I want to prevent user from transitioning out of active route, but at the same time user should be able to transition between sub-routes of current route. I'm can use willTransition event to detect if transition is initiated, but how to detect if transition will exit current route or only transition between subroutes of current route?

The official Ember guide doesn't help in this case. http://emberjs.com/guides/routing/preventing-and-retrying-transitions/

1

1 Answers

0
votes

There may be a better way, but you could easily make it work by inspecting the transition object as:

Em.Route.extend({

  actions: {
    willTransition: function(transition) {
      var name = this.routeName;

      var isTransitionOut = transition.state.handlerInfos.every(function(item){
        return name !== item.name;
      });

      if (isTransitionOut) {
        alert('aborting');
        transition.abort();
      }
    }
  }
});

http://emberjs.jsbin.com/nilac/1/edit