Ember nested route won't show?

2019-09-10 07:36发布

问题:

I've gone over the docs and I can't see what I'm doing wrong.

Router.map

App.Router.map(function(){
  this.resource('users', function(){
    this.resource('user', { path: ':user_id' });
    this.resource('add');
  });
});

handlebar

<script type="text/x-handlebars" id="users/add">
  <h3>Add User</h3>
</script>

I get the proper URL with my link-to: {{#link-to 'add'}}Add User{{/link-to}}

However the contents of my handlebar template for users/add never show?

Here are my Routes

App.UsersRoute = Ember.Route.extend({
  model: function(){
    console.log("Users route triggered");
    return App.Users; 
  }
});

App.UserRoute = Ember.Route.extend({
  model: function(params){
    return App.Users.findBy('id', params.user_id);
  }
});

App.UserAddRoute = App.UserRoute.extend({
  renderTemplate: function(){
    console.log("Users Add Route triggered");
    this.render('users/add'); 
  }
});

Here's my jsbin: http://jsbin.com/denap/3/edit?html,js,output

回答1:

your code had a few errors, as the handlebars template blocks are identified by data-template-name rather than by id. also you could declare add as a nested route than a nested resource - see your updated (& working) jsbin here: http://jsbin.com/yuzedacu/1/edit