@@ -126,10 +126,9 @@ const MobileLanguagePicker = () => {
126
126
let href ;
127
127
let currentPath = location . pathname ;
128
128
129
- // Always use manual construction to avoid Docusaurus URL accumulation bugs
129
+ // Handle docs paths
130
130
if ( currentPath . startsWith ( '/docs/' ) ) {
131
131
// Remove existing locale from docs path
132
- // Handle both /docs/locale/path and /docs/locale patterns
133
132
let cleanPath = currentPath . replace ( / ^ \/ d o c s \/ ( j p | j a | r u | z h | z h - C N ) (? = \/ | $ ) / , '/docs' ) ;
134
133
135
134
// If no locale was removed, we're already on a clean path
@@ -150,22 +149,36 @@ const MobileLanguagePicker = () => {
150
149
}
151
150
}
152
151
} else {
153
- // Fallback for non-docs paths
152
+ // Handle non-docs paths (like home page, blog, etc.)
153
+ // Remove any existing locale prefix first
154
154
let cleanPath = currentPath . replace ( / ^ \/ ( j p | j a | r u | z h | z h - C N ) (? = \/ | $ ) / , '' ) ;
155
155
156
+ // If nothing was removed, we're on a clean path already
156
157
if ( cleanPath === currentPath ) {
158
+ // We're on a path like '/' or '/blog' - no locale prefix to remove
157
159
cleanPath = currentPath ;
158
160
}
159
161
160
- // Ensure path starts with /
162
+ // Ensure path starts with / (in case we removed a locale and left empty string)
161
163
if ( ! cleanPath . startsWith ( '/' ) ) {
162
164
cleanPath = '/' + cleanPath ;
163
165
}
164
166
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
+ }
167
175
} 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
+ }
169
182
}
170
183
}
171
184
@@ -190,4 +203,4 @@ const MobileLanguagePicker = () => {
190
203
) ;
191
204
} ;
192
205
193
- export default MobileLanguagePicker ;
206
+ export default MobileLanguagePicker ;
0 commit comments