question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll back up when navigating?

See original GitHub issue

If I have a link (just an a using use:link for example) somewhere at the bottom of a long page, and press it to navigate to another route, that new page is also scrolled down instead of it starting from the top. How can I workaround this behavior?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
jimmywartingcommented, Mar 1, 2022

my solution in meanwhile:

history.pushState = new Proxy(history.pushState, {
  apply (target, thisArg, argumentsList) {
    // scrollTo(0, 0) <-- order of operation can mather (ty, @t-lock)
    Reflect.apply(target, thisArg, argumentsList)
    scrollTo(0, 0)
  }
})
4reactions
t-lockcommented, Oct 1, 2021

@jimmywarting epic solution – but it runs before navigation, meaning the “back” button loses its scroll position.

However, just putting the scrollTo after the reflect, does the trick! 👌

 history.pushState = new Proxy(history.pushState, {
   apply (target, thisArg, argumentsList) {
     Reflect.apply(target, thisArg, argumentsList);
     scrollTo(0,0);
   }
 });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot scroll back up after scrolling down navigation pane
If it's a one time thing just open Task Manager and right click on File Explorer and restart it.
Read more >
Make navigation appear when scrolling up
I would like the CSS to hide the header/navigation on my website once someone starts scrolling down. It always stays at the top....
Read more >
Restore scroll position when navigating with React Router 6
The page should be scrolled to the top. Recap: Go to page A, scroll down and click a link that takes you to...
Read more >
Navigating PDF pages, Adobe Acrobat
Open and navigate an article thread · To scroll through the article one pane at a time, press Enter or click in the...
Read more >
Twitter app scrolls to top with back button issue gets ...
Now: I press the Back button, but it instantly scrolls up to the top of the thread. So then I have to scroll...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found