2

I have a hierarchy of nested routes in my ember app. I want one of the child routes to bypass rendering it's parent template and render directly into the application template. However, I still want to keep the route hierarchy, because I need the models from the parent routes in the child route. What I did is I defined the renderTemplate hook on the child route to render into the application:

renderTemplate: function() {
  this.render({ into: "application" });
}

This works, but when I then click on a link to the parent route, nothing is rendered. I put together a small jsfiddle to demonstrate this: http://jsfiddle.net/H7gvz/1/ - run it, then click on one of the names, then click on "Index". I expect the PeopleRoute to render the people template but instead nothing is rendered.

Is this a bug or am I doing it totally wrong? What should be the correct way to do this?

1 Answer 1

5

Whenever you use nested routes, transitioning from child route ('people.show') to parent route ('people'), will be redirected to the 'index' route. Rendering your 'people' template in App.PeopleIndexRoute will solve your problem.

App.PeopleIndexRoute = Em.Route.extend({
renderTemplate: function() {
    this.render('people',{ into: "application" });

}  
});

Your working fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

This seems to work for the simple jsfiddle I put together, but unfortunately, it doesn't for the actual case in the project I'm working on. There I have more complicated route hierarchy several levels deep. However, in the end, I managed to find a way to pull the original child route out from the original parent, so I don't have to bypass the parent template rendering anymore. I'm still accepting your answer though, because it solves the question the way I formulated it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.