问题描述
我正在使用 Ember 为我的网站制作一个简单的博客.
I am making a simple blog for my website with Ember.
我的路线:
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
内容.
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.
我尝试在我的 post.js
路由文件中明确指定渲染模板,但事情仍然以相同的方式工作.
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/v1.13.0/routing/rendering-a-template/
我从根本上使用 Ember 是错误的吗?如果我想隐藏父模板内容,我的帖子 URL 不应该是博客的子路由吗?
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?
推荐答案
抱歉,@remi 回答完成了这项工作,但根据惯例,这不是正确的.
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'});
});
});
它隐式创建
Router.map(function() {
this.route('blog', function() {
this.route('index', { path: '/' }); // <------ this one
this.route('post', {path: '/:post_id'});
});
});
因此,如果您有嵌套的路由器,但不想嵌套模板,请将博客模板(和路由)重命名为 index.html .这将类似于重命名:
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:
带 POD
app/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
这记录在官方指南(该链接是最新版本,但也适用于旧版本)
This is documented on the Official guide (the link is for the latest version, but it is also applicable for older ones)
这篇关于Ember 在查看子路由时隐藏父模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论