2
votes

My ember application contains a parent route with two nested routes. After fetching the parent route's model I'll transition to one of the nested routes by default.

The router is as follows

this.resource('parent', {path: '/parent'}, function() {
    this.route('route1', {path: '/route1'});
    this.route('route2', {path: '/route2'});
});

In the parent route

redirect: function()
{
    this.transitionTo('parent.route1');
}

Now this works perfectly fine. But the problem arises when I refresh the page while being on the route "#/parent/route2".

Actually I should get the contents of "route2" but the transitionTo makes the route to render "route1". How can I handle this ?

In addition to this. I'm fetching the parent route's model in the nested routes by using "this.modelFor('parent')".

1

1 Answers

1
votes

Instead of having the redirect in App.Parent, have it in App.ParentIndex.

App.ParentIndexRoute = Ember.Route.extend({
  redirect: function() {
    return this.transitionTo('parent.route1');
  }
});

Demo http://emberjs.jsbin.com/pavomo/2/#/sales/orders/

Note that you get redirected to orders/4 by default if no subroute found.