Skip to content

Commit 189d491

Browse files
committed
Fixed root metadata generator
1 parent 915bf9e commit 189d491

2 files changed

Lines changed: 40 additions & 23 deletions

File tree

src/app/(root)/layout.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
import type { Metadata } from "next";
22
import "../globals.css";
3-
import { getTranslations } from "next-intl/server";
3+
import { getTranslations, setRequestLocale } from "next-intl/server";
4+
import { routing } from '@/i18n/routing';
45

5-
const locale = 'zh-tw';
6-
const t = await getTranslations({ locale, namespace: 'Metadata' });
6+
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise<Metadata> {
7+
const { locale } = await params;
8+
const t = await getTranslations({ locale, namespace: 'Metadata' });
79

8-
export const metadata: Metadata = {
9-
icons: [{ rel: "icon", url: "/logo/twds_circle.svg" }],
10-
title: t('title'),
11-
description: t('description'),
12-
keywords: "networking, security, open source, sustainability, technology, startups, future, Taiwan, sustainability, education, cybersecurity",
13-
authors: [{ name: "Taiwan Digital Streaming Co." }],
14-
openGraph: {
10+
return {
11+
icons: [{ rel: "icon", url: "/logo/twds_circle.svg" }],
1512
title: t('title'),
1613
description: t('description'),
17-
type: "website",
18-
locale: locale === 'zh-tw' ? 'zh_TW' : 'en_US',
19-
url: "https://www.twds.com.tw/",
20-
images: "https://www.twds.com.tw/img/og.png",
21-
},
22-
twitter: {
23-
card: "summary_large_image",
24-
title: t('title'),
25-
description: t('description'),
26-
},
27-
};
14+
keywords: "networking, security, open source, sustainability, technology, startups, future, Taiwan, sustainability, education, cybersecurity",
15+
authors: [{ name: "Taiwan Digital Streaming Co." }],
16+
openGraph: {
17+
title: t('title'),
18+
description: t('description'),
19+
type: "website",
20+
locale: locale === 'zh-tw' ? 'zh_TW' : 'en_US',
21+
url: "https://www.twds.com.tw/",
22+
images: "https://www.twds.com.tw/img/og.png",
23+
},
24+
twitter: {
25+
card: "summary_large_image",
26+
title: t('title'),
27+
description: t('description'),
28+
},
29+
};
30+
}
2831

2932
export default function RootLayout({
3033
children,
3134
}: Readonly<{
3235
children: React.ReactNode;
3336
}>) {
37+
setRequestLocale(routing.defaultLocale);
3438
return (
3539
<html lang="zh-TW">
3640
<body>

src/app/(root)/page.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
import { redirect } from 'next/navigation';
1+
'use client'
2+
3+
import { useEffect } from 'react';
24
import { routing } from '@/i18n/routing';
35

46
export default function RootPage() {
5-
redirect(`/${routing.defaultLocale}`);
7+
useEffect(() => {
8+
window.location.href = `/${routing.defaultLocale}`;
9+
}, []);
10+
11+
return (
12+
<div className="min-h-screen flex items-center justify-center">
13+
<div className="text-center">
14+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-green-500 mx-auto mb-4"></div>
15+
<p className="text-gray-600">Redirecting...</p>
16+
</div>
17+
</div>
18+
);
619
}

0 commit comments

Comments
 (0)