Using iron router version 0.9.4 How to update URL query parameters without changing the browser history?
I have a bunch of select boxes which can update the URL query parameters. In some cases I'd like to update the URL without adding an additional entry into window.history. A lot of templates are dependent on the Router.current().params reactive variable, so I need to update that as well when changing the route.
Iron Router has an optional parameter in the Router.go function which you can pass in {replaceState:true}
. This will update the URL without storing the URL change in the window's history.
This is working in Iron Router 0.9.4
var path = Router.path('myRoute',{_id: myId}, {query: myParams});
Router.go(path, {replaceState: true});
If you are on a newer version of Iron Router, the order of arguments has probably changed a little, according to this github issue this would be the new order :
Router.go(path, {}, {replaceState:true});
You can use vanilla JavaScript:
window.history.replaceState(yourNewUrl);
Here is some some documentation. As it's a modern feature, if you want to support older browsers, you can use a polyfill.
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