#Definitively scroll to top of page on navigation

1 messages · Page 1 of 1 (latest)

feral lion
#

I'm quite confused on the 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?

uncut egretBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)