Iron:router Router.go() call does nothing. Why?

For some odd reason, the following iron:router call does nothing:

Router.go(`/some/path/edit/${id}`)

If I run the call in the console manually, it works! It just doesn’t work in the code where it should happen.

The strange thing is I can fix the problem by simply wrapping the call in a timeout to make the call happen in a future tick:

setTimeout(function() {
  Router.go(`/some/path/edit/${id}`)
}, 0)

Have you ever encountered this problem?

Turns out I’m not the only one: [iron-router] Router.go not working from event but ok from console

Besides deferring the call, we can also solve it by calling preventDefault() on the event.

@tmeasday Maybe this can be fixed in iron:router so neither of the two workarounds is required?

Seems to me that preventDefault() is the correct solution? Or take the href off the link if you don’t want to preventDefault()

1 Like