Scroll to top on navigation

[MAILPOET-2129]
This commit is contained in:
Pavel Dohnal
2019-07-22 15:52:57 +02:00
committed by M. Shull
parent 7dde2149dd
commit 94a25f3f1c
3 changed files with 67 additions and 52 deletions

View File

@@ -0,0 +1,12 @@
import { useEffect } from 'react';
import { withRouter } from 'react-router-dom';
const ScrollToTop = ({ children, location: { pathname } }) => {
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return children || null;
};
export default withRouter(ScrollToTop);

View File

@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import { import {
HashRouter, Switch, Route, Redirect, HashRouter, Switch, Route, Redirect,
} from 'react-router-dom'; } from 'react-router-dom';
import ScrollToTop from 'common/scroll_to_top.jsx';
import StepMethodSelection from './import/step_method_selection.jsx'; import StepMethodSelection from './import/step_method_selection.jsx';
import StepInputValidation from './import/step_input_validation.jsx'; import StepInputValidation from './import/step_input_validation.jsx';
@@ -18,6 +19,7 @@ const ImportSubscribers = () => {
const [stepDataManipulationData, setStepDataManipulationData] = useState({}); const [stepDataManipulationData, setStepDataManipulationData] = useState({});
return ( return (
<HashRouter> <HashRouter>
<ScrollToTop>
<Switch> <Switch>
<Route <Route
path="/step_method_selection" path="/step_method_selection"
@@ -69,6 +71,7 @@ const ImportSubscribers = () => {
render={() => <Redirect to="/step_method_selection" />} render={() => <Redirect to="/step_method_selection" />}
/> />
</Switch> </Switch>
</ScrollToTop>
</HashRouter> </HashRouter>
); );
}; };

View File

@@ -13,7 +13,7 @@ function StepInputValidation({ stepMethodSelectionData, history }) {
useEffect( useEffect(
() => { () => {
if (stepMethodSelectionData === 'undefined') { if (stepMethodSelectionData === undefined) {
history.replace('step_method_selection'); history.replace('step_method_selection');
} }
}, },