2014-12-02 18 views
0

我的问题与此problem有关,因为我有相同的问题。如果我有这样的路线:当发布返回空游标时,显示404未找到'slugs'模板 - 流星 - 铁路由器

this.route('userPage', { 
    path: '/user/:username', 
    waitOn: function() { return [Meteor.subscribe('userPage', this.params.username)]; 
    }, 
    data: function() { 
     return Users.findOne({username: this.params.username}); 
    } 
}); 

和我的订阅看起来是这样的:

Meteor.publish('userPage', function(username) { 
    return Users.find({username: username}, {fields: {'profile': 1, 'username': 1}}); 
}); 

404页将被渲染(这是好的),但在98%左右progress-bar挂起(为什么?)。 如果我有这样的路线:

this.route('chat', { 
     path: '/chat/:slug', 
     waitOn: function() { return [ Meteor.subscribe('chat', this.params.slug), Meteor.subscribe('chatAvatars', this.params.slug) ]; }, 
     data: function() { return Chat.findOne({slug: this.params.slug}); } 
    }); 

和我的订阅像这样:

Meteor.publish('chat', function(slug) { 
    return Chat.find({slug: slug}); 
}); 

Meteor.publish('chatAvatars', function(slug) { 
    var chat = Chat.findOne({slug: slug}); 
    if (chat) { 
     return Users.find({_id: {$in: chat.participants}}, {fields: {'profile.image': 1, 'username': 1}}); 
    } else { 
     return null; 
    } 
}); 

没有404没有找到模板将被渲染。为什么?如果聊天存在,我必须检查我的onBeforeAction吗?

回答

0

你忘记设置为准备

Meteor.publish('chatAvatars', function(slug) { 
var chat = Chat.findOne({slug: slug}); 
if (chat) { 
    return Users.find({_id: {$in: chat.participants}}, {fields: {'profile.image': 1, 'username': 1}}); 
} else { 
    this.ready();//<============here 
} 
}); 
+0

谢谢大家的帮助下发布!现在,未找到404未找到的模板,但是能否告诉我为什么进度栏永远不会结束? – user3475602 2014-12-05 08:37:39

+0

不知何故,您的订阅之一永远不会准备好。你确定你在服务器端没有错误吗?或者你可以给我一个小github回购,我可以检查你做什么? – user3636214 2014-12-05 09:07:03

+0

我目前无法提供github回购,但感谢您的帮助!你知道我怎么能'调试'这个? 'progressDebug'模式并不真正有用:/ – user3475602 2014-12-05 16:40:15