From a6e0fe0906cb77095511af984f157dbe9975433f Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Wed, 12 Apr 2023 22:24:56 +0800 Subject: [PATCH] chore: try --- .dumi/hooks/useLocation.ts | 8 +++++++- .dumi/theme/common/ThemeSwitch/index.tsx | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.dumi/hooks/useLocation.ts b/.dumi/hooks/useLocation.ts index 3499a3bbe2..250b7f1329 100644 --- a/.dumi/hooks/useLocation.ts +++ b/.dumi/hooks/useLocation.ts @@ -1,5 +1,6 @@ import { useLocation as useDumiLocation } from 'dumi'; import * as React from 'react'; +import { useEffect } from 'react'; import useLocale from './useLocale'; function clearPath(path: string) { @@ -7,10 +8,15 @@ function clearPath(path: string) { } export default function useLocation() { - const location = useDumiLocation(); + const originLocation = useDumiLocation(); + const [location, setLocation] = React.useState(originLocation); const { search } = location; const [, localeType] = useLocale(); + useEffect(() => { + setLocation(originLocation); + }, [originLocation]); + const getLink = React.useCallback( (path: string, hash?: string | { cn: string; en: string }) => { let pathname = clearPath(path); diff --git a/.dumi/theme/common/ThemeSwitch/index.tsx b/.dumi/theme/common/ThemeSwitch/index.tsx index 3ca6131929..88eb572751 100644 --- a/.dumi/theme/common/ThemeSwitch/index.tsx +++ b/.dumi/theme/common/ThemeSwitch/index.tsx @@ -1,8 +1,9 @@ import React from 'react'; import { FloatButton } from 'antd'; -import { FormattedMessage, Link, useLocation } from 'dumi'; +import { FormattedMessage, Link } from 'dumi'; import { DarkTheme, CompactTheme } from 'antd-token-previewer/es/icons'; import { BgColorsOutlined } from '@ant-design/icons'; +import useLocation from '../../../hooks/useLocation'; import useSiteToken from '../../../hooks/useSiteToken'; import { getLocalizedPathname, isZhCN } from '../../utils'; import ThemeIcon from './ThemeIcon';