From 14c6b5e2da98cac20cbc5517fe5226bf28fbf1db Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 5 Mar 2022 10:46:52 -0800 Subject: [PATCH] Fixed implementation of unauth language switcher Now we can go implement it for auth --- components/HeaderMenu/index.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/HeaderMenu/index.tsx b/components/HeaderMenu/index.tsx index abff0ba6..2974fda2 100644 --- a/components/HeaderMenu/index.tsx +++ b/components/HeaderMenu/index.tsx @@ -29,7 +29,7 @@ const HeaderMenu = (props: Props) => { const [checked, setChecked] = useState(false) - console.log(`Currently: ${checked} ${cookies['NEXT_LOCALE']}`) + // console.log(`Currently: ${checked} ${cookies['NEXT_LOCALE']}`) useEffect(() => { const locale = cookies['NEXT_LOCALE'] @@ -37,11 +37,10 @@ const HeaderMenu = (props: Props) => { }, [cookies]) function handleCheckedChange(value: boolean) { - setChecked(value) - setCookies('NEXT_LOCALE', (value) ? 'ja' : 'en', { path: '/'}) - - // TODO: How do we persist the current page when changing languages? - window.location.href = '/' + const language = (value) ? 'ja' : 'en' + setCookies('NEXT_LOCALE', language, { path: '/'}) + router.push(router.asPath, undefined, { locale: language }) + // router.reload() } function authItems() {