How to automatically reload a page after routing to a new one


#1

Hi all. I’m playing with iron router right now. I need a function that click on the button and the browser jumps to a new page, and the new page needs to be reloaded. The code is here:

Template.reload.events({
  'click #mybutton': function(){
     var index = ...//randomly generate an index;
     Router.go('/'+index);//I have Router.route("/:index" ) in router.js
     //I want to reload the new page after the going to it
  }

The scenario is that each page ‘/:index’ corresponds to some texts in collection Text. Users can add/remove/modify the texts on the page. If I only use Router.go() here, the texts from the previous page will preserve (and I’m not so sure about the reason). But if the page can be reloaded, the problem can be solved.

I think I need to use document.location.reload(true) here:

Template.reload.events({
  'click #mybutton': function(){
     var index = ...//randomly generate an index;
     Router.go('/'+index);//I have Router.route("/:index" ) in router.js
     document.location.reload(true);
  }

It works well if I made no change to the texts on the previous page. However, if I do change some texts and update the Text collection (i use autoform here), the current page will be reloaded if I click on the button. I’m not sure why it happens and how to fix it. Any suggestions here? Thanks a lot