simple scroll restoration for keeping scroll position
$ npm install --save simple-scroll-restorer
https://simple-scroll-restorer.netlify.app/
$ cd demo
$ npm install .
$ npm run start
-> localhost:8080
https://hostile-architecture.org/
Your app.js
somthing like this
import ScrollRestoreManager from 'simple-scroll-restorer';
mount() {
ScrollRestoreManager.observe();
}
unmount() {
ScrollRestoreManager.unobserve();
}
Your router.js
somthing like this
import ScrollRestoreManager from 'simple-scroll-restorer';
onAfter() {
const savedPosisiton = ScrollRestoreManager.getSavedPostion();
if (!savedPosisiton) {
window.scrollTo(0, 0);
return;
}
window.scrollTo(savedPosisiton.x, savedPosisiton.y);
}