gpt4 book ai didi

reactjs - React 应用程序的 XML 站点地图

转载 作者:数据小太阳 更新时间:2023-10-29 03:00:39 29 4
gpt4 key购买 nike

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

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

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

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

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

最佳答案

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

关于reactjs - React 应用程序的 XML 站点地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42382193/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com