site: remove legacy code for hash jump (#44836)

This commit is contained in:
afc163 2023-09-13 19:08:52 +08:00 committed by GitHub
parent 10c78d3778
commit 72da2678aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn'; import 'dayjs/locale/zh-cn';
import { Helmet, useOutlet, useSiteData } from 'dumi'; import { Helmet, useOutlet } from 'dumi';
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'; import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
import zhCN from 'antd/es/locale/zh_CN'; import zhCN from 'antd/es/locale/zh_CN';
import ConfigProvider from 'antd/es/config-provider'; import ConfigProvider from 'antd/es/config-provider';
@ -30,11 +30,10 @@ const locales = {
const DocLayout: React.FC = () => { const DocLayout: React.FC = () => {
const outlet = useOutlet(); const outlet = useOutlet();
const location = useLocation(); const location = useLocation();
const { pathname, search, hash } = location; const { pathname, search } = location;
const [locale, lang] = useLocale(locales); const [locale, lang] = useLocale(locales);
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null); const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const { direction } = useContext(SiteContext); const { direction } = useContext(SiteContext);
const { loading } = useSiteData();
useLayoutEffect(() => { useLayoutEffect(() => {
if (lang === 'cn') { if (lang === 'cn') {
@ -53,20 +52,10 @@ const DocLayout: React.FC = () => {
} }
}, []); }, []);
// handle hash change or visit page hash from Link component, and jump after async chunk loaded
useEffect(() => { useEffect(() => {
const id = hash.replace('#', '');
if (id) document.getElementById(decodeURIComponent(id))?.scrollIntoView();
}, [loading, hash]);
React.useEffect(() => {
if (typeof (window as any).ga !== 'undefined') { if (typeof (window as any).ga !== 'undefined') {
(window as any).ga('send', 'pageview', pathname + search); (window as any).ga('send', 'pageview', pathname + search);
} }
if (typeof (window as any)._hmt !== 'undefined') {
(window as any)._hmt.push(['_trackPageview', pathname + search]);
}
}, [location]); }, [location]);
const content = useMemo(() => { const content = useMemo(() => {