mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Preserve page's scroll position
This commit is contained in:
parent
e5e484cb30
commit
17a673a69a
@ -2,6 +2,25 @@ import React from 'react';
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import styles from './Page.module.css';
|
import styles from './Page.module.css';
|
||||||
|
|
||||||
export default function Page({ className, children }) {
|
export default class Page extends React.Component {
|
||||||
|
getSnapshotBeforeUpdate() {
|
||||||
|
if (window.pageXOffset === 0 && window.pageYOffset === 0) return null;
|
||||||
|
|
||||||
|
// Return the scrolled position as the snapshot value
|
||||||
|
return { x: window.pageXOffset, y: window.pageYOffset };
|
||||||
|
}
|
||||||
|
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||||
|
if (snapshot !== null) {
|
||||||
|
// Restore the scrolled position after re-rendering
|
||||||
|
window.scrollTo(snapshot.x, snapshot.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* eslint-enable no-unused-vars */
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { className, children } = this.props;
|
||||||
return <div className={classNames(styles.page, className)}>{children}</div>;
|
return <div className={classNames(styles.page, className)}>{children}</div>;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user