微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

FlowRouter 未在单个模板中定义

如何解决FlowRouter 未在单个模板中定义

使用 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 中导入 test.js(在您的示例中为模板):

FlowRouter

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。