Skip to content
Snippets Groups Projects
Commit f66b8570 authored by Luigi Sbailo's avatar Luigi Sbailo
Browse files

Add scroll to top

parent 6296ae36
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import React, { useEffect } from 'react';
import MainPage from './components/MainPage';
import ReproducePage from './components/ReproducePage';
import TutorialsPage from './components/TutorialsPage';
import { Route, Switch, Redirect } from 'react-router-dom';
import {
BrowserRouter as Router,
Route,
Switch,
Redirect,
withRouter,
useLocation
} from 'react-router-dom';
function _ScrollToTop(props) {
const { pathname } = useLocation(); useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]); return props.children
}
const ScrollToTop = withRouter(_ScrollToTop)
export const Routes = () => {
return (
<div>
<Router>
<ScrollToTop>
<Switch>
<Route exact path="/Main" component={MainPage}/>
< Route exact path="/">
......@@ -16,7 +34,9 @@ export const Routes = () => {
<Route exact path="/Reproduce" component={ReproducePage}/>
<Route exact path="/Tutorials" component={TutorialsPage}/>
</Switch>
</ScrollToTop>
</Router>
</div>
);
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment