Next.js Discord

Discord Forum

How can i autoscroll to the very top each time you enter a new route?

Answered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Each time i enter a different route, the scroll maintains the position it had on the previous page.

I've tried scroll={} to try to understand the behavior but i can't figure it out.
I've also tried
useEffect(() => {
     window.scrollTo(0, 0)
}, [pathname])
using a scroller component to wrap my layout
Answered by B33fb0n3
when you using router.push or similar in nextjs, then nextjs automatically does that for you. No need nothing else to archive that
View full answer

5 Replies

Answer
@Sun bear solved?
@B33fb0n3 <@307627520298188820> solved?
Sun bearOP
Sorry forgot to reply, yeah its solved thank you!
happy to help