路由的另一个重要职责是渲染同名字的模板。
比如下面的路由设置,posts
路由渲染模板posts.hbs
,路由new
渲染模板posts/new.hbs
。
Router.map(function() {
this.route('posts', function() {
this.route('new');
});
});
每一个模板都会渲染到父模板的{{outlet}}
上。比如上面的路由设置模板posts.hbs
会渲染到模板application.hbs
的{{outlet}}
上。application.hbs
是所有自定义模板的父模板。模板posts/new.hbs会渲染到模板posts.hbs
的{{outlet}}
上。
如果你想渲染到另外一个模板上也是允许的,但是要在路由中重写renderTemplate
回调方法。
// app/routes/posts.js
import Ember from 'ember';
export default Ember.Route.extend({
// 渲染到favorites模板上
renderTemplate: function() {
this.render('favorites');
}
});
模板的渲染这个知识点比较简单,内容也很少,在前面的 路由、模板的执行、渲染顺序 已经介绍过相关的内容。
转载本站内容时,请务必注明来自W3xue,违者必究。