I have a route /scoreboard/1 where 1 is not a restful id of an object but a court id which I want to use to select games where court.
I have tried this code which sets the session but doesn't load the template. The template loads normally if I remove the event and hard code var court.
this.route('scoreboard',
{
path: '/scoreboard/:_id',
template: 'scoreboard',
onBeforeAction: function () {
Session.set('court', this.params._id);
}
}); //route
I have found that this seems to work. What isn't working is this:
var court = Session.get("court");
console.log(court); -> 1
myGame = Games.findOne({court_id: court});
while this works:
myGame = Games.findOne({court_id: 1});
found it!
var court = parseInt(Session.get('court'));
This works for me:
$ meteor create test
$ cd test
$ meteor add iron:router
test.js:
if (Meteor.isClient) {
Template.scoreboard.id = function() {
return Session.get('court');
}
}
Router.route('/scoreboard/:_id', {
name: 'scoreboard',
path: '/scoreboard/:_id',
template: 'scoreboard',
onBeforeAction: function () {
Session.set('court', this.params._id);
}
});
test.html:
<head>
</head>
<template name="scoreboard">
Scoreboard<br/>
id is: {{id}}
</template>
Then go to localhost:3000/scoreboard/123
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With