mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
Add ScrollToTop component
This commit is contained in:
parent
e0433ca74f
commit
1b36fe2ea1
3 changed files with 21 additions and 1 deletions
|
@ -17,7 +17,7 @@ import withSiteData from '../containers/withSiteData.js';
|
|||
import { withApollo } from 'react-apollo';
|
||||
import { withCookies } from 'react-cookie';
|
||||
import moment from 'moment';
|
||||
import { Switch, Route, BrowserRouter } from 'react-router-dom';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { withRouter} from 'react-router';
|
||||
|
||||
const DummyErrorCatcher = ({ children }) => children;
|
||||
|
@ -142,6 +142,7 @@ class App extends PureComponent {
|
|||
|
||||
return (
|
||||
<IntlProvider locale={this.getLocale()} key={this.getLocale()} messages={Strings[this.getLocale()]}>
|
||||
<Components.ScrollToTop />
|
||||
<div className={`locale-${this.getLocale()}`}>
|
||||
<Components.HeadTags />
|
||||
{/* <Components.RouterHook currentRoute={currentRoute} /> */}
|
||||
|
|
18
packages/vulcan-core/lib/modules/components/ScrollToTop.jsx
Normal file
18
packages/vulcan-core/lib/modules/components/ScrollToTop.jsx
Normal file
|
@ -0,0 +1,18 @@
|
|||
import React, {Component} from 'react';
|
||||
import {withRouter} from 'react-router';
|
||||
import {registerComponent} from 'meteor/vulcan:lib';
|
||||
|
||||
// Scroll restoration based on https://reacttraining.com/react-router/web/guides/scroll-restoration.
|
||||
export default class ScrollToTop extends Component {
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.location !== prevProps.location) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
registerComponent('ScrollToTop', ScrollToTop, withRouter);
|
|
@ -24,6 +24,7 @@ export { default as Flash } from './components/Flash.jsx';
|
|||
export { default as HelloWorld } from './components/HelloWorld.jsx';
|
||||
export { default as Welcome } from './components/Welcome.jsx';
|
||||
export { default as RouterHook } from './components/RouterHook.jsx';
|
||||
export { default as ScrollToTop } from './components/ScrollToTop.jsx';
|
||||
|
||||
export { default as withAccess } from './containers/withAccess.js';
|
||||
export { default as withMessages } from './containers/withMessages.js';
|
||||
|
|
Loading…
Add table
Reference in a new issue