问题描述
使用 Meteor,我从一个默认的 Meteor 项目开始......
meteor create --full
FlowRouter.route('/group/:_id',{
name: 'App.groups.show',action() {
if (!logged_in()) {
FlowRouter.go("App.home");
}
else {
this.render('App_body','Group');
}
},});
router.js 在这里:
/imports/startup/client/router.js
群组模板是这样的:
<template name="Group">
{{> user_group}}
</template>
对于 user_group,我有这个:
Template.user_group.onCreated(function user_groupOnCreated() {
console.log("id",FlowRouter.getParam('_id'));
});
结果:
ReferenceError: FlowRouter is not defined
at Blaze.TemplateInstance.user_groupOnCreated (user-group.js:46)
at template.js:119
at Function.Template._withTemplateInstanceFunc (template.js:490)
at fireCallbacks (template.js:115)
at Blaze.View.<anonymous> (template.js:195)
at fireCallbacks (view.js:276)
at Object.Tracker.nonreactive (tracker.js:603)
at view.js:273
at Object.Blaze._withCurrentView (view.js:533)
at Object.Blaze._fireCallbacks (view.js:272)
我也无权访问模板中的 FlowRouter.go
。
我错过了什么?
解决方法
您需要在每个主动使用它的 js 中导入 test.js
(在您的示例中为模板):
FlowRouter