add ScrollToTop

This commit is contained in:
Dawid Wysokiński 2020-12-20 14:40:02 +01:00
parent f1883eeaf8
commit ec933ce417
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return null;
}
export default ScrollToTop;

View File

@ -4,6 +4,7 @@ import * as ROUTES from '@config/routes';
import { Switch, Route } from 'react-router-dom';
import { CssBaseline } from '@material-ui/core';
import ScrollToTop from '@common/ScrollToTop/ScrollToTop';
import IndexPage from './IndexPage/IndexPage';
import NotFoundPage from './NotFoundPage/NotFoundPage';
@ -24,6 +25,7 @@ function App() {
</Route>
</Switch>
<CssBaseline />
<ScrollToTop />
</Fragment>
);
}