I am having a problem with scrolling, when navigating using react-router.
When I am navigating to a different component it is keeping the scroll position from the last navigation. However I want it to restore and start from the top whenever the navigation is changed.
class App extends Component{
render() {
return(
<BrowserRouter onUpdate={() => window.scrollTo(0, 0)} history={createBrowserHistory()}>
<div style={{display: 'flex'}}>
<div className='navBar'>
<ul style={{listStyleType: 'none'}}>
<li><Link to='/'>Home</Link></li>
<li><Link to='/towns'>Towns</Link></li>
<li><Link to='/pubs'>Pubs</Link></li>
<li><Link to='/venues'>Venues</Link></li>
<li><Link to='/cinemas'>Cinemas</Link></li>
</ul>
</div>
<div style={{flex:1, padding:'0px'}}>
{routes.map((route) => (
<Route
key={route.path}
path={route.path}
exact={route.exact}
component={route.main}
/>
))}
</div>
</div>
</BrowserRouter>
)
}
}
However it doesn't work. I have a feeling the issue is with my style of navigation rather then the window.scrollTo() snippet.