-
Notifications
You must be signed in to change notification settings - Fork 27.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
router.push scroll
config has no effect
#57258
Comments
Hey @alvarlagerlof when we pass scroll: false in router.push then the current scroll position is retained from where the link is clicked. In your case, since there was no scroll because the height of otherpage is less than the view height of the screen and thus scroll position is 0, you were always pointed back to the top. If you want to retain the scroll position of the previous page guess the only way is to store the scrollposition somewhere. |
Aha I was expecting it to have the same effect as router.back where if you go back to a page that you've scrolled previously, it keeps that position when you return. |
Yeah |
Got it! That seems to be the case, I didn't notice that before (and I suspect I might not be the only one misunderstanding the expected behavior, based on some comments in this discussion) I suggested a minor tweak to the wording in the documentation to clarify it: https://github.com/vercel/next.js/pull/57273/files @alvarlagerlof Then I think this issue is not valid anymore, at least not based on how you described it. |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/alvarlagerlof/reproduction-router-push-scroll-false-bug
To Reproduce
Current vs. Expected behavior
Using router.push with
{ scroll: false}
should be able to keep the previous scroll position as per the docs.Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:42:57 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8112 Binaries: Node: 18.17.0 npm: 9.6.7 Yarn: 1.22.19 pnpm: 8.9.2 Relevant Packages: next: 13.5.7-canary.16 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Additional context
No response
The text was updated successfully, but these errors were encountered: