Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Scroll to top on route change in mobile and desktop screens? #130

Open
avinashdvv opened this issue Aug 24, 2017 · 3 comments
Open

Scroll to top on route change in mobile and desktop screens? #130

avinashdvv opened this issue Aug 24, 2017 · 3 comments

Comments

@avinashdvv
Copy link

avinashdvv commented Aug 24, 2017

I am developing a website in react JS. In this website, I am facing a trouble. When we click a link in the mid of the page; then the linked page opens. but in the same position of the page. The page does not take to the header. I realized that there is some problem in scrolling to top after routing to another page.

Need some support, please...

I am using react-slider: ^2.3.2]
@balloob

@theopoenaru
Copy link

Hey realize this is a bit belated but had the same challenge. For an app:

<Sidebar><div id='my-page' /></Sidebar>

solved by setting the router onChange to this:

if (document.getElementById('my-page')) { // onChange called once before my-page renders
    document.getElementById('my-page').parentNode.scrollTop = 0;
}

@jsonkao
Copy link

jsonkao commented Nov 22, 2017

Thanks so much @theopoenaru ! I've had this challenge in my app for at least two months now, and just today have isolated our scroll-reset's breaking to when we installed react-sidebar. This worked perfectly!

@alebrozzoSP
Copy link

Tough. It didn't work for me :(

@markusenglund markusenglund mentioned this issue Jul 30, 2018
4 tasks
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

4 participants