2014-10-29 52 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

相關問題