Loren
Loren

Reputation: 14896

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

Upvotes: 0

Views: 120

Answers (2)

Tarang
Tarang

Reputation: 75965

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.

Upvotes: 1

Jason Cochran
Jason Cochran

Reputation: 316

You are telling the Router to what for a collection subscription. The collection and the subscription both are reactive data sources. So when that collection changes, the waitOn fill fire and update the route including the onAfterAction.

Upvotes: 0

Related Questions