IronRouter 中 yieldTemplates 和渲染到的区别

Difference between yieldTemplates and render to in IronRouter

这两种在模板中使用 yield 的方法有什么区别?对我来说,两者都在做同样的事情:

Router.route('/', {
    name: 'home',
    action: function() {
        this.render('content', { to: 'content' });
        this.render('navigation', { to: 'navigation' });
    }
});

Router.route('/', {
    name: 'home',
    yieldTemplates: {
        'navigation':   { to: 'navigation' },
        'content':      { to: 'content' } 
    }
});

两者都是一样的,看你喜欢哪种风格。

但是 yieldTemplates 已被弃用。它仍然有效,但如果你想使用这种风格,你应该用 yieldRegions 替换 yieldTemplates。

code here

/**
 * The regionTemplates for the RouteController.
 */
RouteController.prototype.lookupRegionTemplates = function () {
  return this.lookupOption('yieldRegions') ||
    // XXX: deprecated
    this.lookupOption('regionTemplates') ||
    this.lookupOption('yieldTemplates') || {};
};

您可以在 iron router guide.

中查看 yieldRegions