简体   繁体   English

EmberJs出口在多个嵌套路线内

[英]EmberJs outlet inside multiple nested route

I do not strictly understand outlets and rendering templates in EmberJS. 我不严格了解EmberJS中的插座和渲染模板。 Until now I have been doing mostly CRUD operations or my routes weren't nested as many times as here so I haven't faced this problem yet. 到现在为止,我主要进行CRUD操作,或者我的路由没有被嵌套那么多次,所以我还没有遇到这个问题。 Using {{outlet}} in parent route was enough. 在父级路由中使用{{outlet}}就足够了。

The problem comes with my approach that I used to. 问题来自于我以前的方法。 Everything works fine when I do visit routes admin/* , but when I try to get into eg admin/organization/{id}/user it renders an admin/organization template what I would want to avoid. 当我确实访问routes admin/* ,一切工作都很好,但是当我尝试进入admin/organization/{id}/user它将呈现我想要避免的admin/organization模板。 I suppose these things can be done using renderTemplate( ) function inside route.js but I can't figure these things out. 我想这些东西是可以做到用renderTemplate(函数里面route.js ,但我不能将这些事情弄清楚。

I recreated my routes structure in [twiddle] 我在[twiddle]中重新创建了路线结构

Could someone explain to me that, please? 有人可以告诉我吗?

Nested routes always have nested templates. 嵌套路由始终具有嵌套模板。 To workaround, you can utilize index route, which exists on every level by default. 要解决此问题,您可以利用默认情况下每个级别都存在的index路由。 Structure of your templates will be like this: 模板的结构将如下所示:

-app
--templates
---admin
----organization
-----index.hbs //template for admin/organization/index route, url: /admin/organization
-----user.hbs //template for admin/organization/user route, url: /admin/organization/user
----index.hbs //template for admin/index route, url: /admin

Note that if some template file does not exist (in my example app/templates/admin.hbs , app/templates/admin/organization.hbs do not exist), it's the same as having .hbs file with only {{outlet}} in it 请注意,如果某些模板文件不存在(在我的示例app/templates/admin.hbsapp/templates/admin/organization.hbs不存在),则与仅具有{{outlet}} .hbs文件相同在里面

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

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