Skip to content

Commit ceec27a

Browse files
ChengaDevclaude
andcommitted
Fix language selector not persisting choice before navigation
Switching to English was redirecting back to the previously saved language because LanguageSelector never called changeLocale() — so localStorage still held the old language when EnglishLayout mounted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 154b1f9 commit ceec27a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/components/LanguageSelector.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useLocalization } from '../contexts/Language/LanguageProvider'
77
const LanguageSelector = () => {
88
const navigate = useNavigate()
99
const location = useLocation()
10-
const { languageCode } = useLocalization()
10+
const { languageCode, changeLocale } = useLocalization()
1111

1212
const handleLanguageChange = (newLang: string) => {
1313
// Use languageCode from context (always correct) rather than useParams,
@@ -16,6 +16,10 @@ const LanguageSelector = () => {
1616
? location.pathname
1717
: (location.pathname.slice(`/${languageCode}`.length) || '/')
1818

19+
// Update localStorage BEFORE navigating so EnglishLayout's useEffect
20+
// reads the correct language and doesn't redirect back.
21+
changeLocale(newLang)
22+
1923
if (newLang === 'en') {
2024
navigate(pagePath)
2125
} else {

0 commit comments

Comments
 (0)