Search code examples
reactjsnext.jsvercel

Next.js | Is there any way to render an .xml file?


I'm trying to render an XML file when pointing to www.example.com/sitemap.xml. Since the project was developed using Next.js, the routing works with the js files stored in the pages directory:

  • example.com/help -> help.js
  • example.com/info -> info.js

So, is there any way to achieve this by avoiding accessing the backend?


Solution

  • Add a static file called sitemap.xml under public directory

    public/sitemap.xml
    

    after build you can access www.yourdomain.com/sitemap.xml

    Read more on static files: https://nextjs.org/docs/basic-features/static-file-serving