Skip to content
Advertisement

FlowRouter is not defined in individual templates

Using Meteor, I started with a default Meteor project with…

meteor create --full

I added a route, in router.js, like so:

FlowRouter.route('/group/:_id', {
  name: 'App.groups.show',
  action() {
    if (!logged_in()) {
      FlowRouter.go("App.home");
    }
    else {
      this.render('App_body', 'Group');
    }
  },
});

router.js is here:

/imports/startup/client/router.js

The Group template is this:

<template name="Group">
  
  {{> user_group}}

</template>

And for user_group, I have this:

Template.user_group.onCreated(function user_groupOnCreated() {
  console.log("id", FlowRouter.getParam('_id'));
});

This results in:

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)

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):

import { FlowRouter } from 'meteor/kadira:flow-router'

Template.user_group.onCreated(function user_groupOnCreated() {
  console.log("id", FlowRouter.getParam('_id'))
})
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement