1
因此,我想創建一個用戶配置文件,列出用戶所發佈的帖子。我的問題是通過每個用戶名通過路由器和Meteor.publish /訂閱。我不斷收到「用戶名未定義」將用戶名傳遞給路由器參數
我想我的問題是:鐵路如何知道「this.params.username」是什麼?該網址應該提供那個嗎?
路由器
Router.route('userProfile',{
path: '/:username',
waitOn: function() {
return Meteor.subscribe('userprofile', this.params.username)},
data: function() {return {posts:Posts.find({username: this.params.username})};},
});
Meteor.publish
Meteor.publish('userprofile', function() {
return Posts.find({username: this.params.username});
});
模板
<template name="userProfile">
<div class="posts">
{{#each posts}}
{{> postItem}}
{{/each}}
</div>
</template>