Question

Is there a general way (i.e. in application-router) to abort transitions if the target (including dynamic ids) matches the current route?

I tried hooking into willTransition but the transition.params I found seem to contain the current ids and I have nothing to compare them to.

Was it helpful?

Solution

The params attribute of the transition will reference the current route's params, not the target. What you need is to look at the models provided to the transition via its providedModels attribute. Your code should look like this:

willTransition: function(transition) {
  if ((this.get('routeName') === transition.targetName) &&
      (this.get('currentModel') === transition.providedModels[transition.targetName])) {
    transition.abort();
    return;
  }

  // ... other code here ...
}

OTHER TIPS

I just tested this in my app and I think it does what you're looking for. Basically you test the job_id in the params against the model.id of your controller.

App.JobRoute = Ember.Route.extend({

  actions: {
    willTransition: function(transition) {
      if (this.controller.get('model.id') == transition.params.job_id) {
        transition.abort();
      }
    }
  }

});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top