I'm working on a project with Next/React. When I click on a button which is supposed to bring me to another page, the scroll position is kept, meaning that I arrive X pixels down on the new page.
I added the following code to the page:
if (window.pageYOffset > 0) {
window.scrollTo(0, 0);
}
It works. But the thing is, before it works, the page is displayed X pixels down around 1 sec or less before it goes to the top.