Reputation: 1307
I'm using iron-router in my apps, but whereas i'm trying to use Blaze hooks systems, i've seen some problem on routing. I thought that "before" hooks was called only once before action method. But in fact, It's called twice, one before onData, and one after onData... All before hooks are played each time.
Why ?
a sample app is available here https://github.com/Rebolon/meteor-sample-simpleVote/tree/bug/routing
Upvotes: 1
Views: 522
Reputation: 75975
As mentioned in the docs
onBeforeAction runs before the action function (possibly many times if reactivity is involved).
This means it runs once when the page loads, and again if there is any reactive variable in it. So if your onBeforeAction
contains a reactive variable, and it changes, then it will run again.
So if you have subscriptions or something that you do in there it will run again. Is is likely that you may be using the same type of reactive component in your data
method. This is why you find it runs multiple times.
Upvotes: 5