I'm using the Router package from meteorite.
Meteor.Router.add
"/article/:id": ->
log "article"
"article"
Whenever the article page/template gets loaded, the callback function in the Router always gets run twice. I'm trying to use the callback function for incrementing the view count of the articles. So this poses a problem (every inc is done twice).
Is this the intended behavior? Or did I do something wrong?
UPDATE
It's actually not always being run twice. It happens when the page is refreshed or for the first time the browser navigates to the page. Regardless, it still poses a problem.
UPDATE:
The culprit is the HTML5-History-API package I'm using for IE 8+ routing support. The solution below will serve to help people with the same setup and problem.
Found a solution. But I'm not sure if this is the intended way for handling this.
"/article/:id": (id) ->
unless this.init
Session.set "articleId", id
Meteor.call "incArticleViews", id
"article"
If there's a better solution, please post it and I'll accept.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With