流星与铁路线PathFor [英] Meteor with Iron Route PathFor

查看:54
本文介绍了流星与铁路线PathFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击用户名时,我希望链接转到其个人资料页面.我正在将Meteor与铁路由器一起使用.以下是定义的路线:

When I click on user's name, I want the link to go to their profile page. I am using Meteor with iron router. Here are the defined routes:

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'});

当我将鼠标悬停在主页上的用户名上时,我得到了错误的链接,但是当我将他们的名字悬停在"/companies/"页面上时,得到了正确的链接.为了生成链接,我使用pathFor "CompanyPage".

I get the incorrect link when I hover over the user's name on the homepage but I get the correct link when I hover their name on the '/companies/' page. In order to generate the link, I use pathFor "CompanyPage".

我是否遗漏了导致主页中网址错误的内容?您需要看什么js或html?让我知道,我将编辑这篇文章.谢谢.

Am I missing something that is causing the incorrect url from the homepage? What js or html you need to have a look at? Let me know and I'll edit this post. Thanks.

推荐答案

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

In order to get the correct link, you have to use the following syntax:

{{pathFor 'CompanyPage' _id=userId }}

this._id应该是用户的ID

Where this._id should be the user's id

发生了什么事

对于带有某种附加标识符的路由,Iron Router在this中寻找相同的标识符名称.如果将this设置为正确的数据上下文,则可以使用,但是对于/路由,则没有定义数据上下文.在CompanyPage上,将数据上下文定义给正确的用户.

For routes with appended identifier of some kind, Iron Router looks for the same identifier name in this. It would work if this is set to the correct data context, however in the case of your / route, you don't have a data context defined. On CompanyPage, the data context is defined to the correct user.

这篇关于流星与铁路线PathFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆