-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(next,docs): rework useRouter to support custom router options
- Loading branch information
Showing
24 changed files
with
629 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Providers from './providers'; | ||
import './globals.css'; | ||
import { notFound } from 'next/navigation'; | ||
import { getMessages } from 'next-intl/server'; | ||
import { routing } from '@/i18n/routing'; | ||
import { NextIntlClientProvider } from 'next-intl'; | ||
|
||
export const metadata = { | ||
title: 'Create Next App', | ||
description: 'Generated by create next app', | ||
}; | ||
|
||
export default async function RootLayout({ | ||
children, | ||
params, | ||
}: { | ||
children: React.ReactNode; | ||
params: Promise<{ locale: string }>; | ||
}) { | ||
// Ensure that the incoming `locale` is valid | ||
const { locale } = await params; | ||
if (!routing.locales.includes(locale as any)) { | ||
notFound(); | ||
} | ||
|
||
// Providing all messages to the client | ||
// side is the easiest way to get started | ||
const messages = await getMessages(); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<body> | ||
<NextIntlClientProvider messages={messages}> | ||
<Providers>{children}</Providers> | ||
</NextIntlClientProvider> | ||
</body> | ||
</html> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createNavigation } from 'next-intl/navigation'; | ||
import { routing } from './routing'; | ||
|
||
export const { Link, redirect, usePathname, useRouter, getPathname } = | ||
createNavigation(routing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getRequestConfig } from 'next-intl/server'; | ||
import { routing } from './routing'; | ||
|
||
export default getRequestConfig(async ({ requestLocale }) => { | ||
// This typically corresponds to the `[locale]` segment | ||
let locale = await requestLocale; | ||
|
||
// Ensure that a valid locale is used | ||
if (!locale || !routing.locales.includes(locale as any)) { | ||
locale = routing.defaultLocale; | ||
} | ||
|
||
return { | ||
locale, | ||
messages: (await import(`../messages/${locale}.json`)).default, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineRouting } from 'next-intl/routing'; | ||
|
||
export const routing = defineRouting({ | ||
// A list of all locales that are supported | ||
locales: ['en', 'fr'], | ||
|
||
// Used when no locale matches | ||
defaultLocale: 'en', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"HomePage": { | ||
"title": "Hello world!", | ||
"about": "Go to the about page" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"HomePage": { | ||
"title": "Bonjour le monde!", | ||
"about": "Aller à la page À propos" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import createMiddleware from 'next-intl/middleware'; | ||
import { routing } from './i18n/routing'; | ||
|
||
export default createMiddleware(routing); | ||
|
||
export const config = { | ||
// Match only internationalized pathnames | ||
matcher: ['/', '/(fr|en)/:path*'], | ||
}; |
Oops, something went wrong.