Skip to content

Commit

Permalink
Revert "site: remove legacy code for hash jump (ant-design#44836)"
Browse files Browse the repository at this point in the history
This reverts commit 72da267.
  • Loading branch information
Wxh16144 committed Oct 10, 2023
1 parent 4f360e4 commit 94a5811
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions .dumi/theme/layouts/DocLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import { Helmet, useOutlet } from 'dumi';
import { Helmet, useOutlet, useSiteData } from 'dumi';
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
import zhCN from 'antd/es/locale/zh_CN';
import ConfigProvider from 'antd/es/config-provider';
Expand Down Expand Up @@ -30,10 +30,11 @@ const locales = {
const DocLayout: React.FC = () => {
const outlet = useOutlet();
const location = useLocation();
const { pathname, search } = location;
const { pathname, search, hash } = location;
const [locale, lang] = useLocale(locales);
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const { direction } = useContext(SiteContext);
const { loading } = useSiteData();

useLayoutEffect(() => {
if (lang === 'cn') {
Expand All @@ -52,10 +53,20 @@ const DocLayout: React.FC = () => {
}
}, []);

// handle hash change or visit page hash from Link component, and jump after async chunk loaded
useEffect(() => {
const id = hash.replace('#', '');

if (id) document.getElementById(decodeURIComponent(id))?.scrollIntoView();
}, [loading, hash]);

React.useEffect(() => {
if (typeof (window as any).ga !== 'undefined') {
(window as any).ga('send', 'pageview', pathname + search);
}
if (typeof (window as any)._hmt !== 'undefined') {
(window as any)._hmt.push(['_trackPageview', pathname + search]);
}
}, [location]);

const content = useMemo(() => {
Expand Down

0 comments on commit 94a5811

Please sign in to comment.