简体   繁体   English

不使用资源出口的emberjs中的嵌套路由

[英]Nested route in emberjs without using the resource outlet

I have a router with corresponding templates for each route (and route objects). 我有一个路由器,该路由器具有每个路由(和路由对象)的相应模板。 I want to be able to display each template independently of its parent, meaning I don't want the nested routes to be rendered to the parent template's outlet. 我希望能够独立于其父模板显示每个模板,这意味着我不希望将嵌套路由呈现给父模板的插座。 Essentially making a separate "page" for each nested route. 本质上,为每个嵌套路线制作一个单独的“页面”。

App.Router.map(function() {
  this.resource('recipes', function() {
    this.route('new');
    this.route('show', { path: '/:recipe_id' });
  });
});

I'm using ember1.0.0-rc1 我正在使用ember1.0.0-rc1

Thanks 谢谢

I want to be able to display each template independently of its parent, meaning I don't want the nested routes to be rendered to the parent template's outlet. 我希望能够独立于其父模板显示每个模板,这意味着我不希望将嵌套路由呈现给父模板的插座。

Maybe stating the obvious but that's exactly what will happen if you don't create a template for the resource. 也许说明了显而易见的事实,但是如果您不为资源创建模板,那将发生的事情。 In your case, if you don't create a recipes.hbs template then ember will render the new.hbs and show.hbs templates into the {{outlet}} in application.hbs . 在你的情况,如果你不创建一个recipes.hbs模板然后烬将呈现new.hbsshow.hbs模板到{{outlet}}application.hbs

NOTE: If you do this, Ember will output a console warning "The immediate parent route did not render into the main outlet ..." 注意:如果执行此操作,Ember将输出一个控制台警告“直接父路由未呈现到主插座中...”。

This is explained in more detail in the ember routing guide 余烬路由指南中对此进行了详细说明

Quick note from the ember guides 余烬指南快速提示

If you define a resource using this.resource and do not supply a function, then the implicit resource.index route is not created. 如果使用this.resource定义资源并且不提供功能,则不会创建隐式的resource.index路由。 In that case, /resource will only use the ResourceRoute, ResourceController, and resource template. 在这种情况下,/ resource将仅使用ResourceRoute,ResourceController和资源模板。

Your routing is fine and @mikegrassotti is correct, although if you want an index for "recipes" without having your "new" and "show" route templates nested inside "recipes"(no master/detail) you will need to create an recipes/index template with no outlet inside. 您的路由选择正确,并且@mikegrassotti是正确的, 尽管如果您想要“食谱”的索引而不将“新”和“显示”路径模板嵌​​套在“食谱”中(无主/明细),则需要创建食谱/ index模板,内部没有插座。

<script type="text/x-handlebars" data-template-name="recipes/index">
<ul>
  {{#each}}
    <li>{{recipe}}</li>  
  {{/each}}
</ul>

You do not need to change your route setup. 您无需更改路由设置。 As Mike mentioned above ember will render the new.hbs and show.hbs templates into the {{outlet}} in application.hbs 就像Mike提到的,余烬将把new.hbs和show.hbs模板渲染到application.hbs中的{{outlet}}中

Ember.js does not support nesting routes, it only supports nesting resources. Ember.js不支持嵌套路由,它仅支持嵌套资源。 The ultimately-nested route can contain a route. 最终嵌套的路线可以包含一条路线。

Think of resources as things, and routes as actions. 将资源视为事物,将路线视为行动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM