Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent scroll behavior between Router.push and Link #15206

Closed
oyeanuj opened this issue Jul 15, 2020 · 4 comments
Closed

Consistent scroll behavior between Router.push and Link #15206

oyeanuj opened this issue Jul 15, 2020 · 4 comments
Milestone

Comments

@oyeanuj
Copy link

oyeanuj commented Jul 15, 2020

Feature request

Is your feature request related to a problem? Please describe.

I noticed that when using Link, you can specify option to prevent scrolling to top but the same option seems missing when using Router.push: https://nextjs.org/docs/api-reference/next/router#routerpush

(Additionally, when using browser back buttons, the same scroll behavior happens)

Describe the solution you'd like

A scroll option in the router.push method to specify whether page should be scrolled to the top or not. This would make the behavior in the method consistent as they are supposed to be parallel methods.

Additional context

It seems like here in the code, there needs to be a check for scroll:

if (hash === '') {
window.scrollTo(0, 0)
return


Finally, thank you for all the work that y'all do, and thank you for creating this wonderful library!

@nfantone
Copy link

nfantone commented Aug 26, 2020

Sharing a possible workaround here as well for anyone stumbling upon this issue.

@Timer
Copy link
Member

Timer commented Dec 30, 2020

Closing as duplicate of #3249

@Timer Timer closed this as completed Dec 30, 2020
@finnss
Copy link

finnss commented Feb 17, 2021

I disagree that this is a duplicate. #3249 is entirely focused on stopping the scroll to the top. I am currently having the issue that router.push jumps my page to the top, which I'd like to avoid in my use-case.

I assume the behaviour was changed to always reset(0, 0) in next@canary.
I (and probably others) sometimes want to keep the scroll position after a push, and some sort of scroll option like we have with the <Link> component seems like the real solution @Timer.

If I'm mistaken and this already exists as an option, my bad! I couldn't find anything in the documentation or any existing issues.

EDIT: Nevermind! scroll is indeed a valid option for router.push: https://github.com/vercel/next.js/blob/canary/packages/next/next-server/lib/router/router.ts#L767
Keeping this comment in case anyone else stumbles upon this issue. A note about this in the documentation might be a good idea:) Thanks again for all the hard work you do!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants