Skip to content

Commit

Permalink
feat: add outer layout
Browse files Browse the repository at this point in the history
  • Loading branch information
aszx87410 committed Aug 31, 2023
1 parent ff9f2b0 commit 491580f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules/
node_modules/
.next/
13 changes: 13 additions & 0 deletions src/app/Heading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client';

import useTranslation from 'next-translate/useTranslation'

export default function Heading() {
const { t } = useTranslation('common')

return (
<div>
<h1>Client: {t`layout-title`}</h1>
</div>
)
}
15 changes: 5 additions & 10 deletions src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ export default function RootLayout({
}) {
const { t, lang } = useTranslation('common')

// Redirect to default locale if lang is not supported. /second-page -> /en/second-page
if (!i18n.locales.includes(lang)) redirect(`/${i18n.defaultLocale}/${lang}`)

return (
<html lang={lang}>
<head />
<body>
<h1>{t`layout-title`}</h1>
{children}
</body>
</html>
<div>
==== inner layout ====
<h2>{t`layout-title`}</h2>
{children}
</div>
)
}
27 changes: 27 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import useTranslation from 'next-translate/useTranslation'
import i18n from '../../i18n'
import { redirect } from 'next/navigation'
import Heading from './Heading'

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const { t, lang } = useTranslation('common')

// Redirect to default locale if lang is not supported. /second-page -> /en/second-page
if (!i18n.locales.includes(lang)) redirect(`/${i18n.defaultLocale}/${lang}`)

return (
<html lang={lang}>
<head />
<body>
==== outer layout ===
<h1>{t`layout-title`}</h1>
<Heading />
{children}
</body>
</html>
)
}

0 comments on commit 491580f

Please sign in to comment.