【问题标题】:Iron Router and this.next()Iron Router 和 this.next()
【发布时间】:2015-05-12 13:55:58
【问题描述】:

我有以下正在运行的路线:

Router.route('/', function () {
  Meteor.call("get_country", function(error, result){

   if(!error){

    if(result === null)
     Session.setDefault("country", "int");
    else{
    if(Countries[result] === null)
      Session.setDefault("country", "int");
    else
      Session.setDefault("country", result);
    }
  Session.setDefault('category', Countries[Session.get("country")]);
  Session.setDefault('sources', Categories[Session.get("country")][Session.get("category")]);
  }
 });
});

但是在控制台中,我得到了

Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?

我不使用 onBeforeAction。 我应该注意警告吗?我该如何解决?

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    非常确定您需要指定要加载/渲染的模板:

    Router.route('/', function () {
      Meteor.call("get_country", function(error, result){
    
       if(!error){
    
        if(result === null)
         Session.setDefault("country", "int");
        else{
        if(Countries[result] === null)
          Session.setDefault("country", "int");
        else
          Session.setDefault("country", result);
        }
      Session.setDefault('category', Countries[Session.get("country")]);
      Session.setDefault('sources', Categories[Session.get("country")][Session.get("category")]);
      }
      //Specify template to render
      this.render('templateNameForHomeRoute');
     });
    });
    

    【讨论】:

    • 但是如果我不想用 Iron-Router 渲染模板呢?
    • @user2409399 然后我建议将您的方法调用放在模板级别:Template.myTemplate.rendered = function() {Meteor.call(...)}
    • 没有方法调用的路由也会发生这种情况。实际上它发生在一条空路线Router.route('/', function () {});
    • @user2409399 正如我所说,你需要指定一个模板来加载/渲染 Router.route('/', function () {this.render('templateName')});我建议指定路由选项而不是函数。 (github.com/iron-meteor/iron-router/blob/devel/…)
    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 2015-08-22
    • 2023-03-12
    • 2017-06-17
    • 1970-01-01
    • 2014-12-15
    • 2016-10-31
    • 2014-05-07
    相关资源
    最近更新 更多