4
0
forked from crowetic/commerce

Make language switcher to change language but stay on the current page

This commit is contained in:
Martin Bavio 2020-10-27 00:06:27 -03:00
parent 6957bd816c
commit 71e0d0a315

View File

@ -32,7 +32,12 @@ const LOCALES_MAP: Record<string, LOCALE_DATA> = {
}
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) => (
<Menu.Item key={locale}>
{({ active }) => (
<Link href="/" locale={locale}>
<Link href={currentPath} locale={locale}>
<a className={cn(s.item, { [s.active]: active })}>
{LOCALES_MAP[locale].name}
</a>