From 71e0d0a31564b8942fd06ba32c5ab634d5de047e Mon Sep 17 00:00:00 2001 From: Martin Bavio Date: Tue, 27 Oct 2020 00:06:27 -0300 Subject: [PATCH] Make language switcher to change language but stay on the current page --- components/core/I18nWidget/I18nWidget.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/core/I18nWidget/I18nWidget.tsx b/components/core/I18nWidget/I18nWidget.tsx index 6bbed6179..428f7bc1f 100644 --- a/components/core/I18nWidget/I18nWidget.tsx +++ b/components/core/I18nWidget/I18nWidget.tsx @@ -32,7 +32,12 @@ const LOCALES_MAP: Record = { } const I18nWidget: FC = () => { - const { locale, locales, defaultLocale = 'en-US' } = useRouter() + const { + locale, + locales, + defaultLocale = 'en-US', + asPath: currentPath, + } = useRouter() const options = locales?.filter((val) => val !== locale) const currentLocale = locale || defaultLocale @@ -59,7 +64,7 @@ const I18nWidget: FC = () => { {options.map((locale) => ( {({ active }) => ( - + {LOCALES_MAP[locale].name}