
Thinking about buying a home? We've got you covered
Get expert advice today
getServerSideProps
It's more likely your site will be dynamic. In this case, we can leverage getServerSideProps to generate an XML sitemap on-demand.
We can create a new page inside the pages directory such as pages/sitemap.xml.js. The goal of this page will be to hit our API to get data that will allow us to know the URLs of our dynamic pages. We will then write an XML file as the response for /sitemap.xml
https://dev.to/aswanth_raveendranek_a2a/generate-dynamic-sitemap-in-next-js-27m9
https://akashrajpurohit.com/blog/how-i-automatically-generate-dynamic-sitemap-in-nextjs/
https://nextjs.org/learn-pages-router/seo/crawling-and-indexing/xml-sitemaps