data(params, qs)
params
{Object} - Serialized route parameters,/route/:_id => { _id: 'str' }
qs
{Object} - Serialized query string,/route/?key=val => { key: 'val' }
- Return: {Mongo.Cursor|Object|[Object]|false|null|void}
.data()
is triggered right after all resources in .waitOn()
and .waitOnResources()
hooks are ready.
FlowRouter.route('/post/:_id', {
name: 'post',
waitOn(params) {
return Meteor.subscribe('post', params._id);
},
data(params, qs) {
return PostsCollection.findOne({_id: params._id});
}
});
FlowRouter.route('/post/:_id', {
name: 'post',
action(params, qs, post) {
this.render('_layout', 'post', { post });
},
waitOn(params) {
return Meteor.subscribe('post', params._id);
},
data(params, qs) {
return PostsCollection.findOne({_id: params._id});
}
});
<!-- in a template -->
<template name="post">
<h1>{{post.title}}</h1>
<p>{{post.text}}</p>
</template>
Returned value from data
hook, will be passed into all other hooks as third argument and to triggersEnter
hooks as fourth argument
FlowRouter.route('/post/:_id', {
name: 'post',
data(params) {
return PostsCollection.findOne({_id: params._id});
},
triggersEnter: [(context, redirect, stop, data) => {
console.log(data);
}]
});