Scroll to top on navigation
[MAILPOET-2129]
This commit is contained in:
12
assets/js/src/common/scroll_to_top.jsx
Normal file
12
assets/js/src/common/scroll_to_top.jsx
Normal 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);
|
@@ -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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -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');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user