-
-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Adapt examples for rootParams
#1619
Open
amannn
wants to merge
9
commits into
feat/support-rootparams
Choose a base branch
from
feat/v4-rootparams
base: feat/support-rootparams
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de3bf0e
feat: Adopt `rootParams`
amannn b188221
wip
amannn 224d560
root redirect
amannn 028a366
Merge remote-tracking branch 'origin/v4' into feat/v4-rootparams
amannn a7930c7
wip
amannn c2af326
Re-introduce `({locale})`
amannn e4eaf31
update playground to nextjs 15 canary and rootparams
amannn 1c6e61a
add test for explicit locale
amannn e2858bd
Merge branch 'feat/support-rootparams' into feat/v4-rootparams
amannn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
13 changes: 4 additions & 9 deletions
13
examples/example-app-router-playground/src/app/[locale]/about/page.tsx
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 |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import {Locale} from 'next-intl'; | ||
import {getLocale} from 'next-intl/server'; | ||
|
||
type Props = { | ||
params: { | ||
locale: Locale; | ||
}; | ||
}; | ||
|
||
export default async function AboutPage({params}: Props) { | ||
const Content = (await import(`./${params.locale}.mdx`)).default; | ||
export default async function AboutPage() { | ||
const locale = await getLocale(); | ||
const Content = (await import(`./${locale}.mdx`)).default; | ||
return <Content />; | ||
} |
11 changes: 2 additions & 9 deletions
11
examples/example-app-router-playground/src/app/[locale]/api/route.ts
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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import {NextRequest, NextResponse} from 'next/server'; | ||
import {Locale} from 'next-intl'; | ||
import {getTranslations} from 'next-intl/server'; | ||
|
||
type Props = { | ||
params: { | ||
locale: Locale; | ||
}; | ||
}; | ||
|
||
export async function GET(request: NextRequest, {params: {locale}}: Props) { | ||
export async function GET(request: NextRequest) { | ||
const name = request.nextUrl.searchParams.get('name'); | ||
if (!name) { | ||
return new Response('Search param `name` was not provided.', {status: 400}); | ||
} | ||
|
||
const t = await getTranslations({locale, namespace: 'ApiRoute'}); | ||
const t = await getTranslations('ApiRoute'); | ||
return NextResponse.json({message: t('hello', {name})}); | ||
} |
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
19 changes: 12 additions & 7 deletions
19
examples/example-app-router-playground/src/app/[locale]/news/[articleId]/page.tsx
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 |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import {Metadata} from 'next'; | ||
import {Locale, useTranslations} from 'next-intl'; | ||
import {useTranslations} from 'next-intl'; | ||
import {getLocale} from 'next-intl/server'; | ||
import {use} from 'react'; | ||
import {getPathname} from '@/i18n/routing'; | ||
|
||
type Props = { | ||
params: { | ||
locale: Locale; | ||
params: Promise<{ | ||
articleId: string; | ||
}; | ||
}>; | ||
}; | ||
|
||
export async function generateMetadata({params}: Props): Promise<Metadata> { | ||
const {articleId} = await params; | ||
const locale = await getLocale(); | ||
|
||
return { | ||
alternates: { | ||
canonical: getPathname({ | ||
href: { | ||
pathname: '/news/[articleId]', | ||
params: {articleId: params.articleId} | ||
params: {articleId} | ||
}, | ||
locale: params.locale | ||
locale | ||
}) | ||
} | ||
}; | ||
} | ||
|
||
export default function NewsArticle({params}: Props) { | ||
const {articleId} = use(params); | ||
const t = useTranslations('NewsArticle'); | ||
return <h1>{t('title', {articleId: params.articleId})}</h1>; | ||
return <h1>{t('title', {articleId})}</h1>; | ||
} |
11 changes: 2 additions & 9 deletions
11
examples/example-app-router-playground/src/app/[locale]/opengraph-image.tsx
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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
import {ImageResponse} from 'next/og'; | ||
import {Locale} from 'next-intl'; | ||
import {getTranslations} from 'next-intl/server'; | ||
|
||
type Props = { | ||
params: { | ||
locale: Locale; | ||
}; | ||
}; | ||
|
||
export default async function Image({params: {locale}}: Props) { | ||
const t = await getTranslations({locale, namespace: 'OpenGraph'}); | ||
export default async function Image() { | ||
const t = await getTranslations('OpenGraph'); | ||
return new ImageResponse(<div style={{fontSize: 128}}>{t('title')}</div>); | ||
} |
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
17 changes: 0 additions & 17 deletions
17
examples/example-app-router-playground/src/app/not-found.tsx
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
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
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
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
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
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
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
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
4 changes: 2 additions & 2 deletions
4
examples/example-app-router/src/app/page.tsx → ...app-router/src/app/(unlocalized)/page.tsx
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import {redirect} from 'next/navigation'; | ||
|
||
// This page only renders when the app is built statically (output: 'export') | ||
export default function RootPage() { | ||
redirect('/en'); | ||
export default function RootRedirect() { | ||
return redirect('/en'); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Revert once in stable