I am trying to set my selectedDocId
upon routing to a page, but Meteor is throwing undefined
. I am using an onBeforeAction
in an attempt to store the id
that is concatenated at the end of my url via /:id
, but I can't get them aligned.
Router.route('speaker', {
path:'/speakers/:_id',
template: 'speaker',
data: function(){
return Speakers.findOne(this.params._id);
},
onBeforeAction: function(){
console.log('speaker route has run');
Session.set('selectedDocId', this._id);
//returns undefined
console.log(this._id);
this.next();
}
});
Template.speaker.helpers({
editingDoc: function(){
return Speakers.findOne({_id: Session.get('selectedDocId')});
}
});
Instead of this._id
, use this.params._id
just like you did in the data
hook.