Skip to content

Commit

Permalink
fix: error build
Browse files Browse the repository at this point in the history
  • Loading branch information
vickyadrii committed Sep 15, 2024
1 parent 4a5936c commit 484478d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
39 changes: 27 additions & 12 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import type { Metadata } from "next";
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NextIntlClientProvider } from "next-intl";
import { getMessages } from "next-intl/server";
import { getMessages, getTranslations, unstable_setRequestLocale } from "next-intl/server";
import { Sora } from "next/font/google";
import "./globals.css";
import Wrapper from "@/components/layout/wrapper";
import { locales } from "@/lib/config";
import { notFound } from "next/navigation";
const sora = Sora({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Welcome to Hammercode!",
description: "Hammercode is a community based in Palu, Indonesia",
type Props = {
params: {
locale: string;
};
children: React.ReactNode;
};

export default async function LocaleRootLayout({
children,
params: { locale },
}: Readonly<{
children: React.ReactNode;
params: { locale: string };
}>) {
export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}

export async function generateMetadata({ params: { locale } }: Props) {
const t = await getTranslations({ locale, namespace: "LocaleLayout" });

return {
title: t("title"),
description: t("description"),
};
}

export default async function LocaleRootLayout({ children, params: { locale } }: Readonly<Props>) {
if (!locales.includes(locale as any)) notFound();

unstable_setRequestLocale(locale);

const messages = await getMessages();

return (
Expand Down
15 changes: 14 additions & 1 deletion src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import Home from "@/features/home";
import { locales } from "@/lib/config";
import { unstable_setRequestLocale } from "next-intl/server";
import { notFound } from "next/navigation";

type Props = {
params: {
locale: string;
};
};

export default function HomePage({ params: { locale } }: Props) {
if (!locales.includes(locale as any)) notFound();
unstable_setRequestLocale(locale);

export default function HomePage() {
return <Home />;
}
15 changes: 14 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { unstable_setRequestLocale } from "next-intl/server";
import { redirect } from "@/lib/navigation";
import { notFound } from "next/navigation";
import { locales } from "@/lib/config";

type Props = {
params: {
locale: string;
};
};

export default function RootPage({ params: { locale } }: Props) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!locales.includes(locale as any)) notFound();
unstable_setRequestLocale(locale);

export default function RootPage() {
redirect("/en");
}
24 changes: 17 additions & 7 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import createMiddleware from "next-intl/middleware";
import { locales } from "./lib/config";
// import { locales } from "./lib/config";
import { NextRequest } from "next/server";

export default createMiddleware({
locales: locales,
defaultLocale: "id",
localePrefix: "as-needed",
});
export default async function middleware(request: NextRequest) {
const defaultLocale = request.headers.get("x-next-intl-locale") || "id";

const handleI18nRouting = createMiddleware({
locales: ["en", "id"],
defaultLocale,
localePrefix: "as-needed",
alternateLinks: false,
});
const response = handleI18nRouting(request);

response.headers.set("x-next-intl-locale", defaultLocale);

return response;
}

export const config = {
// matcher: ["/", "/(id)/:path*"],
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
};

0 comments on commit 484478d

Please sign in to comment.