9cbc4aacd5
* add locale switcher to dynamic GSP page in i18n-routing example * Apply suggestions from code review Co-authored-by: JJ Kasper <jj@jjsweb.site> * Add switcher to other pages as well Co-authored-by: JJ Kasper <jj@jjsweb.site>
43 lines
896 B
JavaScript
43 lines
896 B
JavaScript
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
import LocaleSwitcher from '../components/locale-switcher'
|
|
|
|
export default function GsspPage(props) {
|
|
const router = useRouter()
|
|
const { defaultLocale } = router
|
|
|
|
return (
|
|
<div>
|
|
<h1>getServerSideProps page</h1>
|
|
<p>Current locale: {props.locale}</p>
|
|
<p>Default locale: {defaultLocale}</p>
|
|
<p>Configured locales: {JSON.stringify(props.locales)}</p>
|
|
|
|
<LocaleSwitcher />
|
|
|
|
<Link href="/gsp">
|
|
<a>To getStaticProps page</a>
|
|
</Link>
|
|
<br />
|
|
|
|
<Link href="/gsp/first">
|
|
<a>To dynamic getStaticProps page</a>
|
|
</Link>
|
|
<br />
|
|
|
|
<Link href="/">
|
|
<a>To index page</a>
|
|
</Link>
|
|
<br />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export const getServerSideProps = ({ locale, locales }) => {
|
|
return {
|
|
props: {
|
|
locale,
|
|
locales,
|
|
},
|
|
}
|
|
}
|