Prevent rerender on using back button

Hey guys,
I’m programming a new Meteor project and now have problems with my “search results” page. If I click on a result, I get redirected to another internal page of my project. When I use the back button, the “results” template gets rerendered again. So I lost my current “scroll position”. Problem is, that I can’t save the scolling position, because I save “every seen result” to a collection to not show it again on the next search request.

Is there any way to prevent Meteor from rerendering and deliver the last rendered version (caching)?

Meteor itself does not support “back button” so it must be something with your logic.
Or router, but there are few of them and you did not specify if/which you are using.
Also normally I would expect back button go to search page, not to re-render results.
Provide more info and than mby we will have chance to help you.

I’m using Iron router. For example, I get my results on route “/results”. On that page, I click on a link and get redirected to “/items/123”. Then I click the “back button” of my browser and I’m back on “/results”. Problem here: Now I’m on the top of the page again, not on my leaving position, because Meteor has “rerendered” the template. In my case, I need to disable the automatic rerendering.

look at adding okgrow:router-autoscroll

If you are using React you can use cache-route component and it will cache like a regular web page again

1 Like