React 应用程序的 XML 站点地图 [英] XML sitemap for react app

查看:31
本文介绍了React 应用程序的 XML 站点地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 React 应用程序,我想为其添加一个 sitemap.xml.我已添加此路由以链接到文件(XML 是我的 sitemap.xml):

I have a react app for which I want to add a sitemap.xml. I have added this route to link to the file (XML is my my sitemap.xml):

import XML from './sitemap.xml';    
<Route component={XML} path={'/sitemap.xml'} />

我一直收到这个错误,我明白这意味着我需要向我的 webpack 添加一个 xml 加载器:

I keep getting this error, which I understand it means that I need to add an xml loader to my webpack:

You may need an appropriate loader to handle this file type.

不确定如何选择 xml 加载器,因为我通常可以找到解析器(xml 到 json),而且我不确定在 json 中是否可以使用站点地图.另外,是否有任何其他本地方式可以在不添加任何加载程序的情况下显示 xml 文件?

Not sure how to pick an xml loader as I could mostly find parsers (xml to json) and I am not sure if it's ok to have the sitemap in json. Also, is there any other native way of displaying the xml file without adding any loader?

推荐答案

如果您使用的是 create-react-app,只需将您的 XML 文件放在公共文件夹(node_modules 和 src 文件夹旁边的文件夹)中,然后通过 <代码>{base_url}/{XML_file_name.xml}(例如localhost:3000/sitemap.xml)

If you are using create-react-app, just put your XML file in public folder (a folder beside node_modules and src folders), then access it through {base_url}/{XML_file_name.xml} (e.g. localhost:3000/sitemap.xml)

这篇关于React 应用程序的 XML 站点地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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