Commit b8829639 authored by Sam Chen's avatar Sam Chen Committed by GitHub

fix: scroll to top only when pathname changes (#4180)

parent 62550a4a
...@@ -6,7 +6,7 @@ import TopLevelModals from 'components/TopLevelModals' ...@@ -6,7 +6,7 @@ import TopLevelModals from 'components/TopLevelModals'
import ApeModeQueryParamReader from 'hooks/useApeModeQueryParamReader' import ApeModeQueryParamReader from 'hooks/useApeModeQueryParamReader'
import { lazy, Suspense } from 'react' import { lazy, Suspense } from 'react'
import { useEffect } from 'react' import { useEffect } from 'react'
import { Redirect, Route, Switch, useHistory, useLocation } from 'react-router-dom' import { Redirect, Route, Switch, useLocation } from 'react-router-dom'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { useAnalyticsReporter } from '../components/analytics' import { useAnalyticsReporter } from '../components/analytics'
...@@ -80,20 +80,15 @@ function getCurrentPageFromLocation(locationPathname: string): PageName | undefi ...@@ -80,20 +80,15 @@ function getCurrentPageFromLocation(locationPathname: string): PageName | undefi
} }
export default function App() { export default function App() {
const history = useHistory()
const location = useLocation() const location = useLocation()
const { pathname } = location
const currentPage = getCurrentPageFromLocation(location.pathname) const currentPage = getCurrentPageFromLocation(location.pathname)
useAnalyticsReporter() useAnalyticsReporter()
initializeAnalytics() initializeAnalytics()
useEffect(() => { useEffect(() => {
const unlisten = history.listen(() => { window.scrollTo(0, 0)
window.scrollTo(0, 0) }, [pathname])
})
return () => {
unlisten()
}
}, [history])
return ( return (
<ErrorBoundary> <ErrorBoundary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment