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.

Était-ce utile?

La 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 ...
}

Autres conseils

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();
      }
    }
  }

});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top