Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
8bfa443b
Unverified
Commit
8bfa443b
authored
Nov 04, 2025
by
Joseph
Committed by
GitHub
Nov 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: generateSitemap passes id as promise (#85767)
parent
49933c2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
generate-sitemaps.mdx
...1-app/03-api-reference/04-functions/generate-sitemaps.mdx
+8
-6
No files found.
docs/01-app/03-api-reference/04-functions/generate-sitemaps.mdx
View file @
8bfa443b
...
@@ -24,6 +24,7 @@ Your generated sitemaps will be available at `/.../sitemap/[id].xml`. For exampl
...
@@ -24,6 +24,7 @@ Your generated sitemaps will be available at `/.../sitemap/[id].xml`. For exampl
For
example
,
to
split
a
sitemap
using
`generateSitemaps`
,
return
an
array
of
objects
with
the
sitemap
`id`
.
Then
,
use
the
`id`
to
generate
the
unique
sitemaps
.
For
example
,
to
split
a
sitemap
using
`generateSitemaps`
,
return
an
array
of
objects
with
the
sitemap
`id`
.
Then
,
use
the
`id`
to
generate
the
unique
sitemaps
.
```ts filename="app/product/sitemap.ts" switcher
```ts filename="app/product/sitemap.ts" switcher
import type { MetadataRoute } from 'next'
import { BASE_URL } from '@/app/lib/constants'
import { BASE_URL } from '@/app/lib/constants'
export async function generateSitemaps() {
export async function generateSitemaps() {
...
@@ -31,11 +32,10 @@ export async function generateSitemaps() {
...
@@ -31,11 +32,10 @@ export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
}
}
export default async function sitemap({
export default async function sitemap(props: {
id,
id: Promise<number>
}: {
id: number
}): Promise<MetadataRoute.Sitemap> {
}): Promise<MetadataRoute.Sitemap> {
const id = await props.id
// Google's limit is 50,000 URLs per sitemap
// Google's limit is 50,000 URLs per sitemap
const start = id * 50000
const start = id * 50000
const end = start + 50000
const end = start + 50000
...
@@ -57,7 +57,8 @@ export async function generateSitemaps() {
...
@@ -57,7 +57,8 @@ export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
}
}
export default async function sitemap({ id }) {
export default async function sitemap(props) {
const id = await props.id
// Google's limit is 50,000 URLs per sitemap
// Google's limit is 50,000 URLs per sitemap
const start = id * 50000
const start = id * 50000
const end = start + 50000
const end = start + 50000
...
@@ -65,7 +66,7 @@ export default async function sitemap({ id }) {
...
@@ -65,7 +66,7 @@ export default async function sitemap({ id }) {
`
SELECT
id
,
date
FROM
products
WHERE
id
BETWEEN
$
{
start
}
AND
$
{
end
}
`
`
SELECT
id
,
date
FROM
products
WHERE
id
BETWEEN
$
{
start
}
AND
$
{
end
}
`
)
)
return products.map((product) => ({
return products.map((product) => ({
url: `
$
{
BASE_URL
}
/
product
/
$
{
id
}
`,
url: `
$
{
BASE_URL
}
/
product
/
$
{
product
.
id
}
`,
lastModified: product.date,
lastModified: product.date,
}))
}))
}
}
...
@@ -75,5 +76,6 @@ export default async function sitemap({ id }) {
...
@@ -75,5 +76,6 @@ export default async function sitemap({ id }) {
|
Version
|
Changes
|
|
Version
|
Changes
|
|
---------
|
----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
---------
|
----------------------------------------------------------------------------------------------------------------------------------------------------
|
|
`v16.0.0`
|
The
`id`
values
returned
from
`generateSitemaps`
are
now
passed
as
a
promise
to
the
sitemap
function
.
|
|
`v15.0.0`
|
`generateSitemaps`
now
generates
consistent
URLs
between
development
and
production
|
|
`v15.0.0`
|
`generateSitemaps`
now
generates
consistent
URLs
between
development
and
production
|
|
`v13.3.2`
|
`generateSitemaps`
introduced
.
In
development
,
you
can
view
the
generated
sitemap
on
`/.../sitemap.xml/[id]`
.
For
example
,
`/product/sitemap.xml/1`
.
|
|
`v13.3.2`
|
`generateSitemaps`
introduced
.
In
development
,
you
can
view
the
generated
sitemap
on
`/.../sitemap.xml/[id]`
.
For
example
,
`/product/sitemap.xml/1`
.
|
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment