【问题标题】:Iron Router Action vs OnBeforeActionIron Router Action vs OnBeforeAction
【发布时间】:2015-06-22 23:46:15
【问题描述】:

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

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    action 旨在用于特定模板的路由控制器中。

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

    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'); }
      }
    
    
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      相关资源
      最近更新 更多