fwoeck
fwoeck

Reputation: 293

ember.js: how to abort transitions if target matches current path

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.

Upvotes: 2

Views: 3683

Answers (2)

NudeCanalTroll
NudeCanalTroll

Reputation: 2286

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

Upvotes: 1

Jeremy Green
Jeremy Green

Reputation: 8574

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

});

Upvotes: 0

Related Questions