Skip to content

Commit

Permalink
example to show alternative language change without using Link component
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Sep 2, 2022
1 parent 4942bdb commit b69c464
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions examples/simple/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const Homepage = () => {
const router = useRouter()
const { t } = useTranslation('common')

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const onToggleLanguageClick = (newLocale) => {
const { pathname, asPath, query } = router
router.push({ pathname, query }, asPath, { locale: newLocale })
}

const changeTo = router.locale === 'en' ? 'de' : 'en'

return (
<>
<main>
Expand Down Expand Up @@ -44,12 +52,17 @@ const Homepage = () => {
<div>
<Link
href='/'
locale={router.locale === 'en' ? 'de' : 'en'}
locale={changeTo}
>
<button>
{t('change-locale', { changeTo: router.locale === 'en' ? 'de' : 'en' })}
{t('change-locale', { changeTo })}
</button>
</Link>
{/* alternative language change without using Link component
<button onClick={() => onToggleLanguageClick(changeTo)}>
{t('change-locale', { changeTo })}
</button>
*/}
<Link href='/second-page'>
<button
type='button'
Expand Down

0 comments on commit b69c464

Please sign in to comment.