#router.refresh() resets scroll position

1 messages · Page 1 of 1 (latest)

north agate
#

When I use router.back() it sends me back properly and I'm on the scroll position I was earlier.

However, when I use router.refresh() to refresh data updated in database and use router.back() it always sends me to the top of the previous page. Moreover I feel like it loses "cache" and loads a little longer after router.refresh().

Any idea of how to fix it?

covert pulsarBOT
#

Hi @north agate. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems that the behavior you're experiencing is expected. When you use router.refresh(), it refreshes the data for the currently rendered route and resets the client-side state. This could be why you're always sent back to the top of the page and why it seems to load a little longer after router.refresh().

As for retaining the scroll position, one user suggested storing the scroll position somewhere before calling router.refresh(). However, this solution was not elaborated on in the extracts provided.

Here are the relevant discussions for your reference:

For more detailed information and potential solutions, you might want to check out the Next.js documentation or their GitHub discussions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@north agate kapa.ai is still learning and improving, please let us know how it did by reacting below

north agate
#

@covert pulsar can you find a fix of this issue?

covert pulsarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Hmm, I don't know enough to give you a confident answer yet. The extracts provided do not contain a specific solution to your issue. I recommend checking out the Next.js GitHub discussions (https://github.com/vercel/next.js/discussions) or the Next.js documentation (https://nextjs.org/docs) for more information and potential solutions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: