Skip to content

Commit 9b7e931

Browse files
committed
fix issue with language picker routes
1 parent 71280a5 commit 9b7e931

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/components/MobileSideBarMenu/MobileLanguagePicker.jsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ const MobileLanguagePicker = () => {
126126
let href;
127127
let currentPath = location.pathname;
128128

129-
// Always use manual construction to avoid Docusaurus URL accumulation bugs
129+
// Handle docs paths
130130
if (currentPath.startsWith('/docs/')) {
131131
// Remove existing locale from docs path
132-
// Handle both /docs/locale/path and /docs/locale patterns
133132
let cleanPath = currentPath.replace(/^\/docs\/(jp|ja|ru|zh|zh-CN)(?=\/|$)/, '/docs');
134133

135134
// If no locale was removed, we're already on a clean path
@@ -150,22 +149,36 @@ const MobileLanguagePicker = () => {
150149
}
151150
}
152151
} else {
153-
// Fallback for non-docs paths
152+
// Handle non-docs paths (like home page, blog, etc.)
153+
// Remove any existing locale prefix first
154154
let cleanPath = currentPath.replace(/^\/(jp|ja|ru|zh|zh-CN)(?=\/|$)/, '');
155155

156+
// If nothing was removed, we're on a clean path already
156157
if (cleanPath === currentPath) {
158+
// We're on a path like '/' or '/blog' - no locale prefix to remove
157159
cleanPath = currentPath;
158160
}
159161

160-
// Ensure path starts with /
162+
// Ensure path starts with / (in case we removed a locale and left empty string)
161163
if (!cleanPath.startsWith('/')) {
162164
cleanPath = '/' + cleanPath;
163165
}
164166

165-
if (locale === i18n.defaultLocale || locale === 'en') {
166-
href = cleanPath;
167+
// For home page specifically, handle it differently
168+
if (cleanPath === '/' || cleanPath === '') {
169+
if (locale === i18n.defaultLocale || locale === 'en') {
170+
href = '/';
171+
} else {
172+
// For non-English, go to the docs root for that language
173+
href = `/docs/${locale}/`;
174+
}
167175
} else {
168-
href = `/${locale}${cleanPath}`;
176+
// For other non-docs pages
177+
if (locale === i18n.defaultLocale || locale === 'en') {
178+
href = cleanPath;
179+
} else {
180+
href = `/${locale}${cleanPath}`;
181+
}
169182
}
170183
}
171184

@@ -190,4 +203,4 @@ const MobileLanguagePicker = () => {
190203
);
191204
};
192205

193-
export default MobileLanguagePicker;
206+
export default MobileLanguagePicker;

0 commit comments

Comments
 (0)