Search code examples
meteorpublish-subscribeflow-router

Flowrouter Subscriptions


This is how my flowrouter looks like, I tried all three options shown below: but unable to subscribe

import {CompanySettings} from '../imports/api/companysettingsMaster.js';
// And imported the api also..
FlowRouter.route('/', {
  name: 'home',
  subscriptions: function() {
    // 1.
    return this.register('companySettings', Meteor.subscribe('companySettings'));
    // 2.
    this.register('CompanySettings', Meteor.subscribe('companySettings'));
    // 3.
    return Meteor.subscribe('companySettings');
  },
  action: function() {

    var themeSettings = CompanySettings.findOne({
      "companyId": 101
    });
    if (themeSettings) {
      console.log(themeSettings);
      var scaleProcess = themeSettings.generalSettings.scaleProcess;

      if (scaleProcess == 'retail')
        BlazeLayout.render("retailMainLayout", {
          content: "homepages"
        });
      else {
        BlazeLayout.render("WSEmainLayout", {
          content: "homepages"
        });
      }
    } else {
      console.log('no themeSettings');
    }

  }
});

But, not getting document at the end .. Any suggestions.. Thanks in advance


Solution

  • I got the answer for subscription in flowrouter which is as follows:

    FlowRouter.route('/', {
        waitOn: function () {
           return Meteor.subscribe('companySettings');
        },    
    });
    

    Here companySettings is a name of collection in mongodb