From c049eee0dfcc447a057a777efbf9ba6193a7f926 Mon Sep 17 00:00:00 2001 From: ambar Date: Mon, 18 Mar 2024 12:49:25 +0800 Subject: [PATCH] feat(theme-default): preserve query string on locale change --- .changeset/little-dots-compete.md | 5 +++++ packages/theme-default/src/components/Nav/menuDataHooks.tsx | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/little-dots-compete.md diff --git a/.changeset/little-dots-compete.md b/.changeset/little-dots-compete.md new file mode 100644 index 000000000..2cfec5bc5 --- /dev/null +++ b/.changeset/little-dots-compete.md @@ -0,0 +1,5 @@ +--- +"@rspress/theme-default": minor +--- + +feat(theme-default): preserve query string on locale change diff --git a/packages/theme-default/src/components/Nav/menuDataHooks.tsx b/packages/theme-default/src/components/Nav/menuDataHooks.tsx index da79ad6e9..1c62c8eed 100644 --- a/packages/theme-default/src/components/Nav/menuDataHooks.tsx +++ b/packages/theme-default/src/components/Nav/menuDataHooks.tsx @@ -6,7 +6,7 @@ import { SvgWrapper } from '../SvgWrapper'; export function useTranslationMenuData() { const { siteData, page } = usePageData(); const currentVersion = useVersion(); - const { pathname } = useLocation(); + const { pathname, search } = useLocation(); const defaultLang = siteData.lang || ''; const defaultVersion = siteData.multiVersion.default || ''; const localeLanguages = Object.values( @@ -31,7 +31,7 @@ export function useTranslationMenuData() { items: localeLanguages.map(item => ({ text: item?.label, link: replaceLang( - pathname, + pathname + search, { current: currentLang, target: item.lang,