Skip to content

Commit 7e44437

Browse files
committed
fix for multilingual search
1 parent 056f71d commit 7e44437

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/theme/SearchBar/utils/searchConfig.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,16 @@ export function createSearchNavigator(history, externalUrlRegex, currentLocale)
111111
// If parsing fails, use as-is
112112
}
113113

114-
// If the URL is relative and doesn't already start with /docs, prepend it
114+
// If the URL is relative, prepend the locale-specific baseUrl
115115
// This is needed because history.push expects the full path including baseUrl
116-
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('/docs')) {
117-
url = '/docs' + url;
116+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
117+
// Construct the baseUrl based on locale
118+
const baseUrl = currentLocale !== 'en' ? `/docs/${currentLocale}` : '/docs';
119+
120+
// Only prepend if the URL doesn't already start with the baseUrl
121+
if (!url.startsWith(baseUrl)) {
122+
url = baseUrl + url;
123+
}
118124
}
119125

120126
if (isRegexpStringMatch(externalUrlRegex, url)) {

0 commit comments

Comments
 (0)