rsnext/examples/with-i18n-next-intl/components/Navigation.js
Pavel Mineev 4e79481511
(examples/with-i18n-next-intl): fixes warning (#25928)
### Documentation / Examples

Fixed one of the items from #25854

- Fixes warning from `next-intl`
- Hides locale selector in case if no other location
- Fixes path `next/router` import 
- Removes unused variable

---

- [x] Add the StackBlitz button in README.md
- [x] Make sure the linting passes

[Live demo on StackBlitz](https://stackblitz.com/github/akellbl4/next.js/tree/fix/example-with-i18n-next-intl-missing-other/examples/with-i18n-next-intl)
2021-07-19 23:49:45 +00:00

27 lines
772 B
JavaScript

import { useTranslations } from 'next-intl'
import { useRouter } from 'next/router'
import Link from 'next/link'
export default function Navigation() {
const t = useTranslations('Navigation')
const { locale, locales, route } = useRouter()
const otherLocale = locales?.find((cur) => cur !== locale)
return (
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div style={{ display: 'flex', gap: 10 }}>
<Link href="/">
<a>{t('index')}</a>
</Link>
<Link href="/about">
<a>{t('about')}</a>
</Link>
</div>
{otherLocale && (
<Link href={route} locale={otherLocale}>
<a>{t('switchLocale', { locale: otherLocale })}</a>
</Link>
)}
</div>
)
}