File Author Date Description import { Component } from 'react' ; import { withRouter } from 'react-router-dom' ; class ScrollToTop extends Component < any > { public componentDidUpdate ( prevProps ) { const { hash } = window . location ; if ( hash ) { setTimeout ( ( ) => { const id = hash . replace ( '#' , '' ) ; const element = document . getElementById ( id ) ; if ( element ) { element . scrollIntoView ( ) ; } } , 0 ) ; } else { if ( this . props . location !== prevProps . location ) { window . scrollTo ( 0 , 0 ) ; } } } public render ( ) { return this . props . children ; } } export default withRouter ( ScrollToTop ) ;