2014-10-29 54 views
20

自从将Meteor升级到版本1.0以来,其他人是否从Iron-Router获得以下错误?Meteor v 1.0和Iron:路由器

如果你知道如何解决这个问题,请在这里发帖。

路由调度从未呈现。你忘了拨this.next()onBeforeAction

Router.map(function() { 
    Router.route('profileShow', { 

     waitOn: function() { 
      if (Meteor.user()) { 
       Meteor.subscribe('userData'); 
      } else { 
       this.next(); 
      } 
     }, 

     data: function() { 
      if (Meteor.user()) { 
       return {profile: Meteor.user().profile}; 
      } 
     } 
    }); 
}); 

回答

29

有在铁路由器的最新版本的非向后兼容的改变。迁移指南说:

onRunonBeforeAction钩现在需要向this.next(),并不再采取pause()说法。所以默认行为是相反的。例如,如果您有:

Router.onBeforeAction(function(pause) { 
    if (! Meteor.userId()) { 
    this.render('login'); 
    pause(); 
    } 
}); 

你需要将其更新为

Router.onBeforeAction(function() { 
    if (! Meteor.userId()) { 
    this.render('login'); 
    } else { 
    this.next(); 
    } 
}); 

More information

在你在这种情况下,本书的修正是在onBeforeAction的末尾添加this.next()。然而,你应该宁愿使用waitOn

waitOn: function() { 
    return Meteor.subscribe("userData"); 
} 

这样的话,你可以设置一个loadingTemplateuserData订阅加载将出现。

+3

只是要补充一点,即使消息说它是onBeforeAction,它也可能是onRun导致错误。错误信息可能会更好。 – 2014-12-22 15:34:21

相关问题