NextJs 15 app router. Using a dynamic segment as part of a folder name

NextJs 15 app router. Using a dynamic segment as part of a folder name

I'm trying to create a dynamic route for sitemaps. To do this I want to create a page which can take a page number as part of the folder name and return that page of the sitemap, but I keep getting 404. All the LLMs say I'm doing it right but I can't seem to get it to work and I don't see an example on NextJS site. Searching either so I'm thinking this isn't allowed?

Here is the folder layout. [page] should be the page number of the sitemap to retrieve.

enter image description here

If I change the folder name to /app/sitemap-books-1.xml it works (well 500 but at least it's hitting the route).

Claude code says everything is fine...

Is this allowed?

NextJS 15.3.3

Answer

Ok now Claude says this isn’t allowed. At least it found me an article on how to do it.

Haven’t tried this yet but this is the post. https://guillermodlpa.com/blog/how-to-make-dynamic-large-sitemaps-with-next-js-and-next-sitemap

enter image description here

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions