You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm on 1.0.0-rc1 and also need conventional browser scroll behaviour (preserve scroll position when using the back button, scroll up when you come to a new page).
Any chance you can give us an ETA for getting this into 1.0.0, or a quick-fix until? None of the closed issues matching 'scroll' give a hint..
@darreng see my comment on implementing the behavior "preserve scroll position when using the back button, scroll up when you come to a new page" #2144 (comment)
Activity
heyheyjp commentedon Sep 20, 2015
There's been a lot of discussion in previously filed (and closed) issues on the topic of scroll behavior with 1.0. Check it out! :)
https://github.com/rackt/react-router/issues?utf8=%E2%9C%93&q=is%3Aissue+scroll
LDMFD commentedon Sep 22, 2015
I'm on 1.0.0-rc1 and also need conventional browser scroll behaviour (preserve scroll position when using the back button, scroll up when you come to a new page).
Any chance you can give us an ETA for getting this into 1.0.0, or a quick-fix until? None of the closed issues matching 'scroll' give a hint..
VictorienTardif commentedon Sep 29, 2015
+1
jackmoore commentedon Sep 30, 2015
Use onUpdate, from #2144
nicolashery commentedon Oct 25, 2015
@darreng see my comment on implementing the behavior "preserve scroll position when using the back button, scroll up when you come to a new page" #2144 (comment)
DanielSundberg commentedon Nov 4, 2015
Is the
onUpdate={() => window.scrollTo(0, 0)}
and #2144 (comment) the proposed way to handle this in 1.0.0?I have tried to read through all the issues but have not found anything that makes this clear.
kojuka commentedon Nov 7, 2015
how do I get the current location in the onUpdate() function?
jackmoore commentedon Nov 8, 2015
@webular I don't think you can. I had the same need and switched from using
onUpdate
to history's listen method (first argument is the location object): https://github.com/rackt/history/blob/master/docs/GettingStarted.mdkojuka commentedon Nov 16, 2015
@jackmoore thx
mikestopcontinues commentedon Dec 9, 2015
@webular if you're looking to preserve scroll depth for the back button, you can just use the window.location.
thedamon commentedon Jan 4, 2016
This really deserves a FAQ or a mention in the readme. I have read through a lot of issues and I have no idea what the current stance is on it.
scroll to top on route change
33 remaining items
pedi commentedon Apr 27, 2017
@mmcgahan You solution won't work robustly
Let's say the navigation stack is
-> A -> B
Then we press go back,
POP
-> A
navigate somewhere deep in page A
Then we press go forward, still
POP
action-> A -> B
We will end up with some deep down in page B also
pedi commentedon Apr 27, 2017
Here's a naively implemented solution. It works for me so far.
Do note that there are browser discrepancies not handled (like browser fire on scroll event for push state change etc)
vivmaha commentedon May 5, 2017
I ended up using the
<ScrollToTop>
workaround described in the react-router docs.Here is my implementation, and an example usage (Typescript).