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'
import ApeModeQueryParamReader from 'hooks/useApeModeQueryParamReader'
import { lazy, Suspense } 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 { useAnalyticsReporter } from '../components/analytics'
......@@ -80,20 +80,15 @@ function getCurrentPageFromLocation(locationPathname: string): PageName | undefi
}
export default function App() {
const history = useHistory()
const location = useLocation()
const { pathname } = location
const currentPage = getCurrentPageFromLocation(location.pathname)
useAnalyticsReporter()
initializeAnalytics()
useEffect(() => {
const unlisten = history.listen(() => {
window.scrollTo(0, 0)
})
return () => {
unlisten()
}
}, [history])
window.scrollTo(0, 0)
}, [pathname])
return (
<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