Next.js |有没有办法呈现 .xml 文件? [英] Next.js | Is there any way to render an .xml file?

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

问题描述

我试图在指向 www.example.com/sitemap.xml 时呈现 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

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

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

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