[英]Router doesn't wait for subscription
我的問題是我有兩個相似的路徑,第一個路由器等待我的訂閱並呈現整個模板,但是第二個路由器立即呈現而沒有加載,並且傳遞的數據導致錯誤(因為還沒有訂閱的集合)。 我將代碼粘貼到此處,第二個代碼由於傳遞的模板和數據而有所不同,但其余代碼實際上是相同的。 我只是從鐵路線開始,也許有人可以告訴我哪里出了錯?
Router.map(function() {
this.route('/', {
onBeforeAction: function() {
if (Meteor.user()) {
if (Meteor.user().firstLogin)
this.render("firstLogin");
else
Router.go('/news');
} else {
this.render("start");
}
},
waitOn: function() {
return Meteor.subscribe('allUsers');
},
onAfterAction: function() {
document.title = "someTitle";
},
loadingTemplate: "loading",
});
this.route('users',{
path:'/user/:_id',
layoutTemplate: 'secondLayout',
yieldTemplates: {
'template1': {to: 'center' },
'template2': {to: 'top' },
'template3': {to: 'left' },
'template4': {to: 'right' },
},
waitOn: function(){
return Meteor.subscribe("allUsers");
},
data: function(){
return Meteor.users.findOne({_id:String(this.params._id)});
},
loadingTemplate: "loading",
});
});
您正在使用Lagary路由器。 如果您只是開始。 我建議您使用新的API。 在這種情況下,您可以使用this.ready()
來檢查訂閱是否完成
以下是官方指南中的示例
Router.route('/post/:_id', function () {
// add the subscription handle to our waitlist
this.wait(Meteor.subscribe('item', this.params._id));
// this.ready() is true if all items in the wait list are ready
if (this.ready()) {
this.render();
} else {
this.render('Loading');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.