Skip to content

Commit 3641761

Browse files
committed
use client-side navigation
1 parent 59041c8 commit 3641761

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/components/MobileSideBarMenu/MobileLanguagePicker.jsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,29 @@ const MobileLanguagePicker = ({ onLanguageChange }) => {
8686
};
8787

8888
// Handle language selection
89-
const handleLanguageSelect = (locale, href) => {
89+
const handleLanguageSelect = async (locale, href) => {
9090
setIsOpen(false);
9191

9292
// Notify parent component about language change if callback provided
9393
if (onLanguageChange) {
9494
onLanguageChange(locale, href);
95-
} else {
96-
// Fallback navigation if no callback
95+
}
96+
97+
// Try client-side navigation first
98+
try {
99+
// Use history.push for client-side navigation
100+
const { history } = await import('@docusaurus/router');
101+
history.push(href);
102+
103+
// Force a small delay to allow React to update, then trigger a re-render
104+
setTimeout(() => {
105+
// Force re-render by updating a state or triggering a window event
106+
window.dispatchEvent(new Event('languageChanged'));
107+
}, 100);
108+
109+
} catch (error) {
110+
// Fallback to full page reload if client-side navigation fails
111+
console.warn('Client-side navigation failed, falling back to full reload:', error);
97112
window.location.href = href;
98113
}
99114
};

0 commit comments

Comments
 (0)