Search code examples
meteoriron-router

Why would iron-router ignore waitOn?


onAfterAction is run twice, once before the data arrives, and once after. Why is it run before the data arrives? Also, in this basic version, rendered is called after the data arrives, but in my app, it's called before the data arrives. Any idea why that might be? Basic reproduction:

https://github.com/lorensr/waiton-bug

Items = new Meteor.Collection 'items'

Router.configure
  waitOn: ->
    Meteor.subscribe 'items'

if Meteor.isServer
  Meteor.publish 'items', ->
    Items.find {}

Router.route '/',
  name: 'hello'

enter image description here


Solution

  • You don't have a loadingTemplate defined. Iron Router can't use the loading template if you don't have one so the effect is the waiting effect of waitOn is ignored.

    Simply add the loadingTemplate and it should work.

    The onAfterAction is run once and after. The first when its waiting, the other times when there is a reactive change or the data is ready. If you want something that doesn't do this use onRun instead.