transitionTo("some_route") being aborted ember 2.2.0


#1

// app/router.js

import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('questions');
  this.route('question', { path: "/questions/:question_id" });
});

// app/routes/questions.js

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  correct: "",
  wrong: "",
  model () {
    return this.store.find("question").then(questions => {
      return this.store.find("key", this.get("session.data.authenticated.key")).then(key => {
        this.set("correct", key.get("correct"));
        this.set("wrong", key.get("wrong"));
        return key.get("questions");
      });
    });
  },

 afterModel (model, transition) {
    this.controllerFor("question").set("key", this.get("session.data.authenticated.key"));
    model = model.filter(item => {
     return  this.get("correct").indexOf(item.id) === -1 && this.get("wrong").indexOf(item.id) === -1;
    });
    this.transitionTo("question", model.get("firstObject"));
  }
});

//app/routes/question.js

import Ember from 'ember';

export default Ember.Route.extend({
  model (params) {
    return this.store.find("question", params.question_id);
  },

  setupController (controller, model) {
    controller.set("model", model);
  }
});

//app/controllers/question.js

import Ember from 'ember';

export default Ember.Controller.extend({
  key: "",
  option: "",
  actions: {
    submitQuiz () {
      this.store.findRecord("key", this.get("key")).then(key => {
        key.set("answer", this.get("option"));
        key.save();
      }).then(() => {
        this.transitionToRoute("questions");
      });
    },

    selected (option, elm) {
      this.set("option", option);
      Ember.$(".question_container").find(".selected").removeClass("selected");
      Ember.$("#".concat(elm)).addClass("selected");
    }
  }
});

However, this.transitionToRoute(“questions”) in app/controllers/questions.js is being aborted in the middle of transition. Any idea why that’s happening??? And is there a way to force transition???


Any idea why transitionTo("some route") is being aborted?
#2

It looks to me, that you call transition after findRecord promise instead of key.save(). Have you tried key.save().then(() => {}) ?


#3

I had tried that too. It still doesn’t work.


#4

I think what’s happening is transition to “questions” route gets aborted and the current page with the current model gets loaded instead. However when I manually go to path /questions, I see the proper behavior.