Next.js Discord

Discord Forum

How to have multiple sitemaps?

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
I understand that Nextjs can let you generate dynamic sitemaps on the fly within app -> sitemap.ts file. But this only generate one single sitemap. I have more than 50,000 pages, so I'll need more than one. Apparently, nextjs has this feature available here
https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/metadata-dynamic-routes/app/gsp/sitemap.ts

But it is undocumented within their documentation. I want to generate different sitemaps for example (jobs, blogs, schools, etc). I tried replicating the example in the link, but doesn't seem to work, the sitemap is not able to be found as shown in this open issue
https://github.com/vercel/next.js/issues/53480

I am on the latest Nextjs

14 Replies

@Black carp You can’t use the built in sitemap for NextJS as that is only equipped for a single sitemap
yeah but you can, they just haven't documented it... (idk why)
its been for so many months
Black carp
Right - I used route handlers and https://www.npmjs.com/package/next-sitemap
Id prefer to use their built in, but this works for the time being.
@Black carp I set up a dynamic route and through a hack was able to make sitemaps in buckets of 1000.
Spectacled bearOP
Hey, I was using next-sitemap before as well, but not the most familiar with sitemap generation in general, since I never found the need for multiple sitemaps until now. Can you elaborate on some of the example of the files you have in place and how you structured it (aka how the root sitemap.xml, the other sitemaps, and the route handlers)
Black carp
this is the hacky way I did it
Spectacled bearOP
is that under the pages/api folder?

And I'm assuming your root sitemap.xml is in your public folder, or are you still using the app dir sitemap.ts file? How did you generate the root sitemap dynamically?
Black carp
In the app router as an api route.
/app/api/sitemap-news