#next router
1 messages · Page 1 of 1 (latest)
Hi @supple gazelle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To ensure that the page scrolls to the top when using router.push in Next.js 13, you can set the scroll option to true when calling router.push. By default, the scroll option is set to true, so it should scroll to the top of the page after navigation. However, if it's not working as expected, you can explicitly set the scroll option:
router.push(url, as, { scroll: true });
Here's the relevant extract for reference:
options- Optional object with the following configuration options:scroll- Optional boolean, controls scrolling to the top of the page after navigation. Defaults totrue
Source: Next.js > api-reference > next > router > next/router > router object > router.push > Part 1 (https://nextjs.org/docs/api-reference/next/router)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@supple gazelle kapa.ai is still learning and improving, please let us how it did by reacting below
@daring kettle this does not work with next/navigation in next 13 app dir.
Let me check the knowledge base for you again. One moment! :books: