What is the best way to scroll to the top when a route changes in react router dom v6?
In the past, I used a solution from this StackOverflow post to make my page automatically scroll to the top every time a route changed with react-router-dom v5. However, this solution no longer works for me since I have upgraded to react-router-dom v6.
I also attempted the suggestion provided in this other StackOverflow post, but unfortunately, it did not solve my issue either.
Finally, after exploring this GitHub discussion thread, where they recommend using the preload
prop to trigger scrollTo(0,0)
, I tried it and still encountered the same problem.