Iron Router Action 与 OnBeforeAction

Iron Router Action vs OnBeforeAction

iron:router 的 actiononBeforeAction 有什么区别?最初我的猜测是 action 是一个始终处于活动状态的路由挂钩,而 onBeforeAction 仅在路由呈现之前执行。另外,我将如何描述所有路线的全球行动。 Router.onBeforeAction 有效,因此我可以为所有路由全局定义一个挂钩,但是我不能以相同的方式使用 Router.action。也许我只是误解了 action 在做什么。

action 旨在用于特定模板的 Route Controllers。

您需要注意这是可选的,因为默认操作的行为是自动呈现路线及其布局和区域。 所以如果你想在使用路由控制器时改变默认行为,你可以这样做:

this.PostAdController = RouteController.extend({

  'template' : 'InsertPostTemplate',
  'subscriptions' : function(){ /* subs here */ },

  'action'   : function(){
    // this could be empty in most cases, but:
    if (this.ready()){ this.render(); } else { this.render('Loading'); }
  }


});

因此,如果订阅尚未准备好,您可以使用该代码呈现加载模板。