Definitively scroll to top of page on navigation
Unanswered
Tomistoma posted this in #help-forum
TomistomaOP
I'm quite confused on the
The reason I find it more confusing is because that's also not the behaviour I observed. When my links were
Unfortunately, the client has reported the same scroll bug even when
Firstly, what does
Link component. The docs state:Defaults to true. The default scrolling behavior of <Link> in Next.js is to maintain scroll position [....]So to me,
scroll=true will maintin scroll position, and therefore scroll=false wont maintain position (i.e. it will go to the top). However, it then says:When scroll = {false}, Next.js will not attempt to scroll to the first Page element.which contradicts that idea, in which case, what does
scroll=false even do?The reason I find it more confusing is because that's also not the behaviour I observed. When my links were
scroll=true, scroll position would be maintained on the page (which is bad in my case due to dynamic content loading after the scroll, which screws up the position). However, when I set scroll=false, every time I navigated I would be taken to the top of the page, no exception.Unfortunately, the client has reported the same scroll bug even when
scroll=false, and after much experimenting I have narrowed it down to the fact that scroll=false doesn't quite scroll to the top of the page when the browser window is small, it is between a few tens to a few hundreds of pixels away from the top, which will then get messed up by the dynamic content.Firstly, what does
scroll=false even mean/do? And secondly, how do I force navigation to always scroll to the top? Do I just use window.scroll on in a client component in the root layout?1 Reply
TomistomaOP
For now I have done a window.scrollTo on navigation, but to me that does feel a bit janky. Every site I have created, and most sites I have ever used I expect to be taken to the top of the page when navigating. So for maintaining scroll position to not only be the default, but also not even have a way to opt into forcing scroll to top feels like a big oversight.