sitemap.xml
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.
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.
In production, your generated sitemaps will be available at /.../sitemap/[id].xml
. For example, /product/sitemap/1.xml
.
In development, you can view the generated sitemap on /.../sitemap.xml/[id]
. For example, /product/sitemap.xml/1
. This difference is temporary and will follow the production format.
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 |
---|---|
v13.4.5 | Add changeFrequency and priority attributes to sitemaps. |
v13.3.0 | sitemap introduced. |