fix: make header a parallel route
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
"use client"
|
||||
|
||||
import { useParams } from "next/navigation"
|
||||
|
||||
import LanguageSwitcher from "@/components/Current/Header/LanguageSwitcher"
|
||||
|
||||
import { baseUrls } from "../../_constants"
|
||||
|
||||
import { LangParams } from "@/types/params"
|
||||
|
||||
export default function Error() {
|
||||
const params = useParams<LangParams>()
|
||||
return <LanguageSwitcher urls={baseUrls} lang={params.lang} />
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import LanguageSwitcher from "@/components/Current/Header/LanguageSwitcher"
|
||||
|
||||
import { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default async function LanguageSwitcherRoute({
|
||||
params,
|
||||
}: PageArgs<LangParams>) {
|
||||
const urls = await serverClient().contentstack.config.languageSwitcher()
|
||||
|
||||
return <LanguageSwitcher urls={urls} lang={params.lang} />
|
||||
}
|
||||
21
app/[lang]/(live)/@header/[...uri]/layout.tsx
Normal file
21
app/[lang]/(live)/@header/[...uri]/layout.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ReactNode } from "react"
|
||||
|
||||
import Header from "@/components/Current/Header"
|
||||
|
||||
import { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export default function HeaderLayout({
|
||||
params,
|
||||
languageSwitcher,
|
||||
children,
|
||||
}: PageArgs<LangParams> & {
|
||||
languageSwitcher: ReactNode
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Header lang={params.lang} languageSwitcher={languageSwitcher} />
|
||||
{children}
|
||||
</>
|
||||
)
|
||||
}
|
||||
3
app/[lang]/(live)/@header/[...uri]/page.tsx
Normal file
3
app/[lang]/(live)/@header/[...uri]/page.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function EmptyHeaderPage() {
|
||||
return null
|
||||
}
|
||||
10
app/[lang]/(live)/@header/_constants.ts
Normal file
10
app/[lang]/(live)/@header/_constants.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { LanguageSwitcherData } from "@/types/requests/languageSwitcher"
|
||||
|
||||
export const baseUrls: LanguageSwitcherData = {
|
||||
da: { url: "/da/" },
|
||||
de: { url: "/de/" },
|
||||
en: { url: "/en/" },
|
||||
fi: { url: "/fi/" },
|
||||
no: { url: "/no/" },
|
||||
sv: { url: "/sv/" },
|
||||
}
|
||||
6
app/[lang]/(live)/@header/error.tsx
Normal file
6
app/[lang]/(live)/@header/error.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
"use client"
|
||||
|
||||
export default function Error() {
|
||||
// Don't return any header if error
|
||||
return null
|
||||
}
|
||||
15
app/[lang]/(live)/@header/page.tsx
Normal file
15
app/[lang]/(live)/@header/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import Header from "@/components/Current/Header"
|
||||
import LanguageSwitcher from "@/components/Current/Header/LanguageSwitcher"
|
||||
|
||||
import { baseUrls } from "./_constants"
|
||||
|
||||
import { LangParams, PageArgs } from "@/types/params"
|
||||
|
||||
export async function LanguageSwitcherRoute({ params }: PageArgs<LangParams>) {
|
||||
return (
|
||||
<Header
|
||||
lang={params.lang}
|
||||
languageSwitcher={<LanguageSwitcher urls={baseUrls} lang={params.lang} />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
"use client"
|
||||
|
||||
export default function Error({ error }: any) {
|
||||
// Don't return any content if error
|
||||
return null
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default async function DefaultLanguageSwitcher() {
|
||||
return null
|
||||
}
|
||||
@@ -24,10 +24,10 @@ export const metadata: Metadata = {
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
params,
|
||||
languageSwitcher,
|
||||
header,
|
||||
}: React.PropsWithChildren<
|
||||
LayoutArgs<LangParams> & {
|
||||
languageSwitcher: React.ReactNode
|
||||
header: React.ReactNode
|
||||
}
|
||||
>) {
|
||||
const { defaultLocale, locale, messages } = await getIntl()
|
||||
@@ -55,10 +55,7 @@ export default async function RootLayout({
|
||||
<body>
|
||||
<ServerIntlProvider intl={{ defaultLocale, locale, messages }}>
|
||||
<TrpcProvider lang={params.lang}>
|
||||
<Header
|
||||
lang={params.lang}
|
||||
languageSwitcher={languageSwitcher}
|
||||
/>
|
||||
{header}
|
||||
{children}
|
||||
<Footer lang={params.lang} />
|
||||
</TrpcProvider>
|
||||
|
||||
25
components/Current/Header/LanguageSwitcher/index.tsx
Normal file
25
components/Current/Header/LanguageSwitcher/index.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import Desktop from "./Desktop"
|
||||
import Mobile from "./Mobile"
|
||||
|
||||
import styles from "./languageSwitcher.module.css"
|
||||
|
||||
import { LangParams } from "@/types/params"
|
||||
import { LanguageSwitcherData } from "@/types/requests/languageSwitcher"
|
||||
|
||||
type LanguageSwitcherProps = LangParams & { urls: LanguageSwitcherData }
|
||||
|
||||
export default function LanguageSwitcher({
|
||||
urls,
|
||||
lang,
|
||||
}: LanguageSwitcherProps) {
|
||||
return (
|
||||
<>
|
||||
<section className={styles.desktop}>
|
||||
<Desktop currentLanguage={lang} urls={urls} />
|
||||
</section>
|
||||
<section className={styles.mobile}>
|
||||
<Mobile currentLanguage={lang} urls={urls} />
|
||||
</section>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user