路由的另外一个重要职责是渲染同名字的模板。app
好比下面的路由设置,posts路由渲染模板posts.hbs,路由new渲染模板posts/new.hbs。post
Router.map(function() { this.route('posts', function() { this.route('new'); }); });
每个模板都会渲染到父模板的{{outlet}}上。好比上面的路由设置模板posts.hbs会渲染到模板application.hbs的{{outlet}}上。application.hbs是全部自定义模板的父模板。模板posts/new.hbs会渲染到模板posts.hbs的{{outlet}}上。this
若是你想渲染到另一个模板上也是容许的,可是要在路由中重写renderTemplate回调。spa
// app/routes/posts.js import Ember from 'ember'; export default Ember.Route.extend({ // 渲染到favorites模板上 renderTemplate: function() { this.render('favorites'); } });
模板的渲染这个知识点比较简单,内容也不多,在前面的《Ember.js 入门指南——番外篇,路由、模板的执行、渲染顺序》已经介绍过相关的内容。.net