默认加载规则
在emberjs中,类的名字是很有用的,它连接各个方法的方式默认是根据各个类的名字。
App.Router.map(function() {
this.resource('posts', function() { // the `posts` route
this.route('favorites'); // the `posts.favorites` route
this.resource('post'); // the `post` route
});
});
资源的名称与路由,控制器或模板的起始名称一致。即使post资源被嵌套了,它的路由的名称 仍是App.PostRoute, 控制器名称是App.PostController,模板名称是post.
自定义加载规则
当然,如果不想使用默认加载的方式,那么会提供一个方式来进行自定义加载的对象。
如果不想渲染与路由处理方法相关联的那个模板,那你就要实现renderTemplate 钩子来覆盖默认行为。
App.PostsRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('favoritePost');
}
});
如果你希望使用一个不同的控制器来取代路由处理方法默认的控制器,那就需要在传递的参数中附上controller的名称。
App.PostsRoute = Ember.Route.extend({
renderTemplate: function() {
this.render({ controller: 'favoritePost' });
}
});