Ember: Regression in rc7 - transitionTo in route activate no longer works as expected


#1

For translation purposes, I need to switch to a route in which I do some initialisation of the new language settings and then transition back to the initial application page.

See a working example with Ember rc6 on http://jsfiddle.net/cyclomarc/dpDuM/2/

Flow: When clicking Show page1, show the contents of page 1, when clicking on Update language, transition to i18Redirect route and in this route activate, transition to page 2. thus, after the transition, the shown page should be page 2.

In Ember rc7, this no longer works. See JSFiddle of same codde on http://jsfiddle.net/cyclomarc/p3yVP/1/

App.Page1Controller = Ember.ObjectController.extend({
  //When clicking update language goto I18redirect route
  updateLanguage: function (lang) {
    this.transitionToRoute('i18redirect');
  }
})

App.I18redirectRoute = Ember.Route.extend({
  activate: function () {
    alert("Arrived in i18Redirect route > Do transition to page 2")
    this.transitionTo('page2');
  }
});

The console log indicates "transitioned into page2’, but the URL and the view show a blank page. It looks like the page 2 content is not rendered in the outlet (in my sample, the outlet has a red border).

Is this a regression ?

According to the documentation, I need to use this.transitionToRoute when calling the method from within a controller, whereas in case of a route itself (thus in the activate of a route), I need to use this.transitionTo. This is how I implemented the code, but the transitionTo in the route is not working in rc 7 …


#2

If we add a simple button with action into i18redirect template, and handle it’s action in I18redirectRoute like so

App.I18redirectRoute = Ember.Route.extend({
     events: {
        test: function() {
            this.transitionTo('page2');
        }
    }
});

everything works so transitionTo works. My guess is you’re handling transition in a wrong hook. We can use redirect hook (A hook you can implement to optionally redirect to another route.) but it is deprecated in favor of using the afterModel. So

App.I18redirectRoute = Ember.Route.extend({
    afterModel: function() {
        this.transitionTo('page2');
    }
});

now it works as expected.


#3

Indeed works when hooking to afterModel and thus not in the route activate. Many thanks. Marc