Skip to content

Commit 4ffe77e

Browse files
authored
fix: incorrect conventional 2-level nav in localized routes (#1849)
1 parent 804836f commit 4ffe77e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/client/theme-api/useNavData.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
IUserNavItems,
77
IUserNavMode,
88
} from './types';
9+
import { getLocaleClearPath } from './useSidebarData';
910
import {
1011
getLocaleNav,
1112
pickRouteSortMeta,
@@ -64,7 +65,10 @@ export const useNavData = () => {
6465
.sort(([a], [b]) => a.split('/').length - b.split('/').length)
6566
// convert sidebar data to nav data
6667
.reduce<Record<string, INavItems[0]>>((ret, [link, groups]) => {
67-
const [, parentPath, restPath] = link.match(/^(\/[^/]+)([^]+)?$/)!;
68+
const [, parentPath, restPath] = `/${getLocaleClearPath(
69+
link.replace(/^\//, ''),
70+
locale,
71+
)}`.match(/^(\/[^/]+)([^]+)?$/)!;
6872
const isNestedNav = Boolean(restPath) && is2LevelNav;
6973
const [firstMeta, secondMeta] = Object.values(routes).reduce<
7074
{

src/client/theme-api/useSidebarData.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515

1616
const DEFAULT_GROUP_STUB_TITLE = '$default-group-title';
1717

18-
const getLocaleClearPath = (routePath: string, locale: ILocalesConfig[0]) => {
18+
export const getLocaleClearPath = (
19+
routePath: string,
20+
locale: ILocalesConfig[0],
21+
) => {
1922
return 'base' in locale
2023
? routePath.replace(locale.base.slice(1), '').replace(/^\//, '')
2124
: routePath;

0 commit comments

Comments
 (0)