流星与铁路线 PathFor

Meteor with Iron Route PathFor

当我点击用户名时,我希望 link 转到他们的个人资料页面。我正在将 Meteor 与铁路由器一起使用。以下是定义的路线:

Router.route('/', { name: 'JobsList'}); //homepage with all users

//this is where the user's profile is located and works:
Router.route('/company/:_id/', {
 name: 'CompanyPage',
 data: function() { return Meteor.users.findOne(this.params._id); }
});

//this page shows all users with url that works:
Router.route('/companies/', {name: 'CompaniesList'});

当我将鼠标悬停在主页上的用户名上时,我得到了不正确的 link,但是当我将鼠标悬停在“/companies/”页面上时,我得到了正确的 link。为了生成 link,我使用 pathFor "CompanyPage".

我是否遗漏了导致主页上 url 不正确的内容?你需要看什么js或html?让我知道,我会编辑这个 post。谢谢

为了获得正确的 link,您必须使用以下语法:

{{pathFor 'CompanyPage' _id=userId }}

其中this._id应该是用户的id

发生了什么:

对于带有某种附加标识符的路由,Iron Router 在 this 中查找相同的标识符名称。如果 this 设置为正确的数据上下文,它将起作用,但是对于 / 路由,您没有定义数据上下文。在 CompanyPage 上,数据上下文被定义为正确的用户。