Search code examples
meteoriron-routerhtml5-history

Iron Router redirect without killing back button functionality


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.

  1. What is the best way around this?
  2. Is there any good reason why we shouldn't just replace rather than push the history.state by default for this.redirect()?

Solution

  • 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