How to scroll to top every time React router change?

How to scroll to top every time React router changed?

First, create a component to handle scroll event like this:




If you'd like to use a class component:




Second, import your scroll-top component and put it at the top of your app, but inside Router


© 2019 4codev

Created with love by Sil.