mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 14:57:22 +03:00
Created component to scroll to top
This commit is contained in:
parent
ad29e2fa5d
commit
ec6b11d9c9
2 changed files with 26 additions and 1 deletions
22
src/common/ScrollToTop.js
Normal file
22
src/common/ScrollToTop.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { withRouter } from 'react-router-dom'
|
||||||
|
|
||||||
|
export class ScrollToTop extends React.Component {
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
const { location, window } = this.props;
|
||||||
|
|
||||||
|
if (location !== prevProps.location) {
|
||||||
|
window.scrollTo(0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollToTop.defaultProps = {
|
||||||
|
window
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withRouter(ScrollToTop);
|
|
@ -8,6 +8,7 @@ import ReduxThunk from 'redux-thunk';
|
||||||
|
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
import ScrollToTop from './common/ScrollToTop'
|
||||||
import reducers from './reducers';
|
import reducers from './reducers';
|
||||||
import registerServiceWorker from './registerServiceWorker';
|
import registerServiceWorker from './registerServiceWorker';
|
||||||
|
|
||||||
|
@ -21,7 +22,9 @@ const store = createStore(reducers, composeEnhancers(
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<App />
|
<ScrollToTop>
|
||||||
|
<App />
|
||||||
|
</ScrollToTop>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
|
|
Loading…
Reference in a new issue