查看子路由时,Ember隐藏父模板 [英] Ember hide parent template when viewing sub-route
问题描述
我的路线:
Router.map(function(){
this.route('home',{path:'/'});
this.route('blog',function ){
this.route('post',{path:'/:post_id'});
});
});
我想要这样,当我点击 / blog
并卷起 / blog /:post_id
我隐藏 blog.hbs
文件的内容并且只显示 blog / post.hbs
内容。
我尝试在我的 post.js
路由文件,但事情保持不变。
导出默认值Ember.Route.extend({
model:function(params){
return this.store.findRecord('post',params.post_id,{reload:true});
},
renderTemplate:function(){
this.render('blog / post');
}
});
阅读本文档中没有提到任何其他想法。
https://guides.emberjs我从根本上使用了Ember错误的?com / v1.13.0 / routing / rendering-a-template /
如果我想隐藏父模板内容,我的帖子网址是不是Blog的子路径?
对不起,@ remi回答这个工作,但按照惯例是不正确的。
当您创建这样的东西:
Router.map function(){
this.route('blog',function(){
this.route('post',{path:'/:post_id'});
});
});
隐含创建
Router.map(function(){
this.route('blog',function(){
this.route('index',{path:'/'}) ; // <------ this one
this.route('post',{path:'/:post_id'});
});
});
所以,如果你有嵌套的路由器,但是不想嵌套模板,重命名博客模板(和路线)索引。这将是重命名:
POD
应用程序/blog/route.js - > app / blog / index / route.js
app / blog / template.hbs - > app / blog / index / template.hbs
无POD
app / routes / blog.js - > app / routes / blog / index.js
app / templates / blog.hbs - > app / templates / blog / index.hbs
这是记录在官方指南(链接是最新版本,但也适用于较旧版本)
I am making a simple blog for my website with Ember.
My routes:
Router.map(function() {
this.route('home', { path: '/' });
this.route('blog', function() {
this.route('post', {path: '/:post_id'});
});
});
I want it so when I click on a post in /blog
and wind up at /blog/:post_id
I hide the content of the blog.hbs
file and only show the blog/post.hbs
content.
I tried specifying the render template explicitly in my post.js
route file, but things kept working in the same fashion.
export default Ember.Route.extend({
model: function(params) {
return this.store.findRecord('post', params.post_id, { reload: true });
},
renderTemplate: function() {
this.render('blog/post');
}
});
Reading through the documentation here didn't cue me into any other ideas.
https://guides.emberjs.com/v1.13.0/routing/rendering-a-template/
Am I fundamentally using Ember wrong? Should my post URL not be a sub-route of Blog if I want to hide a parent templates content?
Sorry, @remi answer do the job, but it is not the correct according to the convention.
When you create something like this:
Router.map(function() {
this.route('blog', function() {
this.route('post', {path: '/:post_id'});
});
});
It implicit creates
Router.map(function() {
this.route('blog', function() {
this.route('index', { path: '/' }); // <------ this one
this.route('post', {path: '/:post_id'});
});
});
So, if you got nested router, but don't want to nest templates, rename the blog template (and route) to index. It will be something like renaming:
with POD
app/blog/route.js -> app/blog/index/route.js
app/blog/template.hbs -> app/blog/index/template.hbs
No POD
app/routes/blog.js -> app/routes/blog/index.js
app/templates/blog.hbs -> app/templates/blog/index.hbs
This is documented on the Official guide (the link is for the latest version, but it is also applicable for older ones)
这篇关于查看子路由时,Ember隐藏父模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!