diff --git a/landing/landing.react.js b/landing/landing.react.js index 5f8a65ca1..2e0c3ba5c 100644 --- a/landing/landing.react.js +++ b/landing/landing.react.js @@ -1,58 +1,61 @@ // @flow import * as React from 'react'; -import { useRouteMatch } from 'react-router-dom'; +import { useLocation, useRouteMatch } from 'react-router-dom'; import AppLanding from './app-landing.react'; import Footer from './footer.react'; import Header from './header.react'; import Keyservers from './keyservers.react'; import Privacy from './privacy.react'; import Support from './support.react'; import Terms from './terms.react'; -import useScrollToTop from './useScrollToTop.react'; export type LandingPageName = | 'app' | 'keyservers' | 'privacy' | 'terms' | 'support'; type ActivePage = { name: LandingPageName, node: React.Node }; function Landing(): React.Node { - useScrollToTop(); + const { pathname } = useLocation(); + React.useEffect(() => { + window?.scrollTo(0, 0); + }, [pathname]); + const onPrivacy = useRouteMatch({ path: '/privacy' }); const onTerms = useRouteMatch({ path: '/terms' }); const onSupport = useRouteMatch({ path: '/support' }); const onKeyservers = useRouteMatch({ path: '/keyservers' }); const isLegalPage: boolean = React.useMemo( () => !!(onPrivacy || onTerms || onSupport), [onPrivacy, onSupport, onTerms], ); const activePage: ActivePage = React.useMemo(() => { if (onPrivacy) { return { name: 'privacy', node: }; } else if (onTerms) { return { name: 'terms', node: }; } else if (onSupport) { return { name: 'support', node: }; } else if (onKeyservers) { return { name: 'keyservers', node: }; } else { return { name: 'app', node: }; } }, [onKeyservers, onPrivacy, onSupport, onTerms]); return (
{activePage.node}
); } export default Landing; diff --git a/landing/useScrollToTop.react.js b/landing/useScrollToTop.react.js deleted file mode 100644 index 5472aee86..000000000 --- a/landing/useScrollToTop.react.js +++ /dev/null @@ -1,19 +0,0 @@ -// @flow -import * as React from 'react'; -import { useHistory } from 'react-router-dom'; - -function useScrollToTop(): void { - const history = useHistory(); - - return React.useEffect(() => { - const unlisten = history.listen(() => { - window.scrollTo(0, 0); - }); - - return () => { - unlisten(); - }; - }, [history.location.pathname, history]); -} - -export default useScrollToTop;