FlowRouter 没有在单独的模板中定义
FlowRouter is not defined in individual templates
使用 Meteor,我从一个默认的 Meteor 项目开始......
meteor create --full
我在router.js中添加了一条路线,像这样:
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 中导入 FlowRouter
(在您的示例中为模板):
import { FlowRouter } from 'meteor/kadira:flow-router'
Template.user_group.onCreated(function user_groupOnCreated() {
console.log("id", FlowRouter.getParam('_id'))
})
使用 Meteor,我从一个默认的 Meteor 项目开始......
meteor create --full
我在router.js中添加了一条路线,像这样:
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 中导入 FlowRouter
(在您的示例中为模板):
import { FlowRouter } from 'meteor/kadira:flow-router'
Template.user_group.onCreated(function user_groupOnCreated() {
console.log("id", FlowRouter.getParam('_id'))
})