ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Bug: transition into a child which renders into parent outlet and transition back yield an empty template

Open darthdeus opened this issue 13 years ago • 8 comments

If I have the following router

App.Router.map(function() {
  this.resource("posts", { path: "/" }, function() {
    this.resource("post", { path: "/:post_id" }, function() {
      this.route("edit", { path: "/edit" });
    });
  });
});

and I specify the edit route so that it renders into the posts outlet

App.PostEditRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render("post/edit", { into: "posts" });
  }
});

then transitioning to post, post.edit and back to post will render nothing on the last post route.

Here's a JSBin which reproduces the issue

darthdeus avatar Jan 31 '13 22:01 darthdeus

In general, you should only be nesting routes when you have nested outlets. Since you aren't nesting the post views, I would recommend the following setup: http://jsbin.com/ogorab/29/edit. The problem you're seeing is that your edit route, by rendering into posts is actually wiping out the post template. However, you never left the post view, so when you transition back to post, it doesn't realize that any re-rendering is necessary. This is an issue of organization and not an actual bug.

wagenet avatar Feb 01 '13 01:02 wagenet

The problem I noticed with your suggestion is that linkTo then no longer applies "active" to what is conceptually (at least in the user's mind) the parent. For example with these routes

App.Router.map(function() {
  this.resource("panel", { path: "/" }, function() {
    this.route("posts", { path: "/posts" });
    this.route("post", { path: "/posts/:post_id" });
  });
});

When you use {{linkTo "posts"}}Posts{{/linkTo}} in the panel template, when you visit the /posts/1 the link to posts no longer has the active class applied to it.

curthasselschwert avatar Feb 01 '13 02:02 curthasselschwert

@curthasselschwert I think that's something you'll have to address on your own. Resources are intended to go hand in hand with nested outlets.

wagenet avatar Feb 01 '13 02:02 wagenet

Any work around for this?

NkS90 avatar Feb 12 '13 09:02 NkS90

@matt001 only un-nesting the resources

darthdeus avatar Feb 12 '13 09:02 darthdeus

Anything new about this? This really frustrates me since I developing an app where I need long semantic links like locaton/2/lessons/4/material/3 so I need nested routes, but not nested templates. Here is question about it -- http://stackoverflow.com/questions/16510647/understanding-ember-routes

H1D avatar May 12 '13 18:05 H1D

So how do you handle this active problem with the link helper.

eskimoblood avatar Jan 26 '14 14:01 eskimoblood

This is an issue for me as well for the same reason as @H1D.

It's unfortunate that you can't safely override which outlet a route's template is rendered into. Makes me wonder why renderTemplate even exists?

I have the following requirements for the project I'm working on:

  1. the parent route's link-to must be active when you're on the logical child route
  2. the logical child route must replace its parent route's render area
  3. no regression issues e.g. browser back button shouldn't break rendering

I am sad that I can't do these simple things. I've now spent many hours looking into possible alternatives and can't find one that covers all 3 of my needs.

I have learned that Ember expects nested resource routes to be rendered at the same time as their parent. This is silly. The web is naturally hierarchical. When I start on a home page of a website, I don't click into a subsection 2 times and find all 3 levels of content displaying at once. Instead, we see each click going deeper into a nested hierarchy that is logically organized. This is why breadcrumbs exist; the URL is its own form of breadcrumbs.

I don't expect my whining to change anything, but I want to make it clear than this scenario should be easy and instead, with Ember, it's painful. I am disappoint.

For others interested in understanding the issue and the expected solution, see this fine article: http://hashrocket.com/blog/posts/ember-routing-the-when-and-why-of-nesting and https://stackoverflow.com/questions/15163869/nested-routes-rendering-into-same-template-outlet-breaks-on-browser-back-button

brendensuarez avatar May 30 '15 01:05 brendensuarez