Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Preserve page's scroll position
Sammy-T17a673a69a62
diff --git a/components/layout/Page.js b/components/layout/Page.jsindex 28492ddfe..3fbd76732 100644--- a/components/layout/Page.js+++ b/components/layout/Page.js@@ -2,6 +2,25 @@ import React from 'react';import classNames from 'classnames';import styles from './Page.module.css';-export default function Page({ className, children }) {- return <div className={classNames(styles.page, className)}>{children}</div>;+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>;+ }}