Meteor with railroad track
When I click on a username, I want the link to go to my profile page. I am using Meteor with an iron router. Here are the specific routes:
Router.route('/', { name: 'JobsList'}); //homepage with all users
//this is where the user 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'});
I get the wrong link when I hover over the username on the homepage, but I get the right link when I find my name on the '/ companies /' page. To create a link I am using pathFor "CompanyPage"
.
Am I missing something that is causing the wrong url on the homepage? What js or html do you need to look at? Let me know and I will edit this post. Thank.
source to share
To get the correct link, you must use the following syntax:
{{pathFor 'CompanyPage' _id=userId }}
If this._id should be user id
What's happening:
For routes with an appended identifier of some type, Iron Router looks for the same identifier name in the this
. It will work if the parameter is this
set to the correct data context, however, in the case of your route /
, you don't have a specific data context. In CompanyPage, the data context is defined by the correct user.
source to share