简体   繁体   中英

Ignoring scroll event when browser back button is clicked

In my site, list page loads all data in table rows. It keeps loading when user scrolls to the bottom of page(infinite scroll). This works fine. User can click a link from row and lands on another page on subdomain. When user clicks back button to list page , it fires scroll event and loads data. Sometime scroll event fired few time(say 3 to 5 api calls happens)

Site is built with Vuejs. I have tried few suggestion like window.onpopstate , vuejs' navigation guards. window.onpopstate doesn't work. Vuejs' beforeRouteEnter not helping. Because even before a flag is captured in beforeRouteEnter , scroll event fires.

Is there any way to stop scroll event being fired by back button click?

This is possibly what you are looking for:

if ( 'scrollRestoration' in history ) {
  history.scrollRestoration = 'manual';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM