Skip to content

Commit

Permalink
Set up shared pathname navigation for next-intl and make main layou…
Browse files Browse the repository at this point in the history
…t statically rendered
  • Loading branch information
MocicaRazvan authored and GabrielMajeri committed Jan 16, 2024
1 parent f265a72 commit 472eb94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import { unstable_setRequestLocale } from "next-intl/server";

import { locales } from "@/i18n";

import "./globals.css";

const inter = Inter({ subsets: ["latin"] });
Expand All @@ -8,6 +12,9 @@ export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}

type LayoutProps = {
children: React.ReactNode;
Expand All @@ -20,6 +27,10 @@ export default function RootLayout({
children,
params: { locale },
}: LayoutProps) {
// Cache the request locale using a temporary API, to make it available to downstream components.
// See https://next-intl-docs.vercel.app/docs/getting-started/app-router#add-unstable_setrequestlocale-to-all-layouts-and-pages for more details.
unstable_setRequestLocale(locale);

return (
<html lang={locale}>
<body className={inter.className}>{children}</body>
Expand Down
5 changes: 5 additions & 0 deletions src/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createSharedPathnamesNavigation } from "next-intl/navigation";
import { locales } from "./i18n";

export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales });

0 comments on commit 472eb94

Please sign in to comment.