From 4ffe77ef36dc995dc4ea28ee767e66936e3805dc Mon Sep 17 00:00:00 2001 From: ayang <75017711+ayangweb@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:03:02 +0800 Subject: [PATCH] fix: incorrect conventional 2-level nav in localized routes (#1849) --- src/client/theme-api/useNavData.ts | 6 +++++- src/client/theme-api/useSidebarData.ts | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/theme-api/useNavData.ts b/src/client/theme-api/useNavData.ts index 55104d36f3..0ff36339da 100644 --- a/src/client/theme-api/useNavData.ts +++ b/src/client/theme-api/useNavData.ts @@ -6,6 +6,7 @@ import type { IUserNavItems, IUserNavMode, } from './types'; +import { getLocaleClearPath } from './useSidebarData'; import { getLocaleNav, pickRouteSortMeta, @@ -64,7 +65,10 @@ export const useNavData = () => { .sort(([a], [b]) => a.split('/').length - b.split('/').length) // convert sidebar data to nav data .reduce>((ret, [link, groups]) => { - const [, parentPath, restPath] = link.match(/^(\/[^/]+)([^]+)?$/)!; + const [, parentPath, restPath] = `/${getLocaleClearPath( + link.replace(/^\//, ''), + locale, + )}`.match(/^(\/[^/]+)([^]+)?$/)!; const isNestedNav = Boolean(restPath) && is2LevelNav; const [firstMeta, secondMeta] = Object.values(routes).reduce< { diff --git a/src/client/theme-api/useSidebarData.ts b/src/client/theme-api/useSidebarData.ts index 5b82c32cce..31e42db939 100644 --- a/src/client/theme-api/useSidebarData.ts +++ b/src/client/theme-api/useSidebarData.ts @@ -15,7 +15,10 @@ import { const DEFAULT_GROUP_STUB_TITLE = '$default-group-title'; -const getLocaleClearPath = (routePath: string, locale: ILocalesConfig[0]) => { +export const getLocaleClearPath = ( + routePath: string, + locale: ILocalesConfig[0], +) => { return 'base' in locale ? routePath.replace(locale.base.slice(1), '').replace(/^\//, '') : routePath;