[英]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'))
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.