Next.js |有什么方法可以呈现 .xml 文件? [英] Next.js | Is there any way to render an .xml file?

查看:16
本文介绍了Next.js |有什么方法可以呈现 .xml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当指向 www.example.com/sitemap.xml.由于该项目是使用 Next.js 开发的,因此路由使用存储在 pages 目录中的 js 文件:

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?

推荐答案

在public目录下添加静态文件sitemap.xml

Add a static file called sitemap.xml under public directory

public/sitemap.xml

构建后您可以访问 www.yourdomain.com/sitemap.xml

详细了解静态文件:https://nextjs.org/docs/basic-features/static-file-serving

这篇关于Next.js |有什么方法可以呈现 .xml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆