sitemap.xml
API Reference for the sitemap.xml file.
sitemap.(xml|js|ts)
is a special file that matches the Sitemaps XML format to help search engine crawlers index your site more efficiently.
Sitemap files (.xml)
For smaller applications, you can create a sitemap.xml
file and place it in the root of your app
directory.
Generating a sitemap using code (.js, .ts)
You can use the sitemap.(js|ts)
file convention to programmatically generate a sitemap by exporting a default function that returns an array of URLs. If using TypeScript, a Sitemap
type is available.
Good to know: sitemap.js
is a special Route Handler that is cached by default unless it uses a Dynamic API or dynamic config option.
Output:
Image Sitemaps
You can use images
property to create image sitemaps. Learn more details in the Google Developer Docs.
Output:
Video Sitemaps
You can use videos
property to create video sitemaps. Learn more details in the Google Developer Docs.
Output:
Generate a localized Sitemap
Output:
Generating multiple sitemaps
While a single sitemap will work for most applications. For large web applications, you may need to split a sitemap into multiple files.
There are two ways you can create multiple sitemaps:
- By nesting
sitemap.(xml|js|ts)
inside multiple route segments e.g.app/sitemap.xml
andapp/products/sitemap.xml
. - By using the
generateSitemaps
function.
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.
Your generated sitemaps will be available at /.../sitemap/[id]
. For example, /product/sitemap/1.xml
.
See the generateSitemaps
API reference for more information.
Returns
The default function exported from sitemap.(xml|ts|js)
should return an array of objects with the following properties:
Version History
Version | Changes |
---|---|
v14.2.0 | Add localizations support. |
v13.4.14 | Add changeFrequency and priority attributes to sitemaps. |
v13.3.0 | sitemap introduced. |