Using Meteor, I started with a default Meteor project with…
JavaScript
x
2
1
meteor create --full
2
I added a route, in router.js, like so:
JavaScript
1
12
12
1
FlowRouter.route('/group/:_id', {
2
name: 'App.groups.show',
3
action() {
4
if (!logged_in()) {
5
FlowRouter.go("App.home");
6
}
7
else {
8
this.render('App_body', 'Group');
9
}
10
},
11
});
12
router.js is here:
JavaScript
1
2
1
/imports/startup/client/router.js
2
The Group template is this:
JavaScript
1
6
1
<template name="Group">
2
3
{{> user_group}}
4
5
</template>
6
And for user_group, I have this:
JavaScript
1
4
1
Template.user_group.onCreated(function user_groupOnCreated() {
2
console.log("id", FlowRouter.getParam('_id'));
3
});
4
This results in:
JavaScript
1
12
12
1
ReferenceError: FlowRouter is not defined
2
at Blaze.TemplateInstance.user_groupOnCreated (user-group.js:46)
3
at template.js:119
4
at Function.Template._withTemplateInstanceFunc (template.js:490)
5
at fireCallbacks (template.js:115)
6
at Blaze.View.<anonymous> (template.js:195)
7
at fireCallbacks (view.js:276)
8
at Object.Tracker.nonreactive (tracker.js:603)
9
at view.js:273
10
at Object.Blaze._withCurrentView (view.js:533)
11
at Object.Blaze._fireCallbacks (view.js:272)
12
I also do not have access to FlowRouter.go
in my templates.
What am I missing?
Advertisement
Answer
You need to import FlowRouter
in every js that actively uses it (in your example the Template):
JavaScript
1
6
1
import { FlowRouter } from 'meteor/kadira:flow-router'
2
3
Template.user_group.onCreated(function user_groupOnCreated() {
4
console.log("id", FlowRouter.getParam('_id'))
5
})
6