I am using Iron Router in a fairly complex app and have some routes that redirect users to other internal routes (for example, "/"
always redirects to "/dashboard"
).
We have been dealing with this by just adding e.g. Router.go("/dashboard")
, or (confusingly but equally ineffective) this.redirect("/dashboard")
to the first route's action
hook.
The problem is that this breaks the browser's back button: you fleetingly land back on the route that has the redirect action, which then redirects you right back to where you were.
history.state
by default for this.redirect()
?We had the same problem in our app. In 0.9.4 (and probably some earlier versions), you can add {replaceState: true}
as the last argument to Router.go
. For more details, see this issue. Note that as of this writing, it looks like this has not been integrated into the 1.0.x code.
For anyone still wondering, a fix for this issue is scheduled for the next release of Iron Router: https://github.com/EventedMind/iron-router/issues/764
There you will be able to use this.redirect() from within your route hooks, which will replace the state by default
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