Javascript 铁路流星
当我点击用户名时,我希望链接转到他们的个人资料页面。我用的是带有铁路由器的流星。以下是定义的路线:Javascript 铁路流星,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,当我点击用户名时,我希望链接转到他们的个人资料页面。我用的是带有铁路由器的流星。以下是定义的路线: 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() { r
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'});
当我将鼠标悬停在主页上的用户名上时,我得到了不正确的链接,但当我将用户名悬停在“/companys/”页面上时,我得到了正确的链接。为了生成链接,我使用了“CompanyPage”的路径
我是否遗漏了导致主页url不正确的内容?您需要查看哪些js或html?让我知道,我会编辑这篇文章。谢谢。为了获得正确的链接,您必须使用以下语法:
{{pathFor 'CompanyPage' _id=userId }}
其中,.\u id应该是用户的id
正在发生的事情:
对于带有某种附加标识符的路由,Iron Router在
中查找相同的标识符名称。如果将此
设置为正确的数据上下文,则可以使用,但是在/
路由的情况下,您没有定义数据上下文。在CompanyPage上,为正确的用户定义了数据上下文 嗨,那没用。我还要声明链接的id与jobpage相同。我在同一个页面上有一个链接,指向他们的工作页面。ie:作业/abcdefg
。他们的个人资料链接也指向公司/abcdefg
。某个地方发生冲突?您必须将this.\u id
替换为用户id。