Template 的渲染

Route 的一大作用就是进行 template 渲染,默认情况下渲染的 template 和 route 是同名的:

Router.map(function() {
  this.route('posts', function() {
    this.route('new');
  });
});

posts 会渲染 posts.hbsposts.new 会渲染 posts/new.hbs

每个 template 都会渲染在 parent route template 的 outlet 中,比如 posts.hbs 会渲染在 application.hbs 中的 outlet,posts/new.hbs 会渲染在 posts.hbs 的 outlet 中。

如果想修改默认渲染的 template 名称可以使用,templateName 属性:

import Route from '@ember/routing/route';

export default Route.extend({
  templateName: 'posts/favorite-posts'
});

Route 还提供了 renderTemplate() hook 来对 template 的渲染进行更多的控制,比如指定特定的 outlet 和 controller。

© 三月沙 all right reserved,powered by GitbookUpdated at 2022-01-22 10:25:17

results matching ""

    No results matching ""