Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在react服务器呈现的应用程序中访问公共url上的sitemap.xml_Javascript_Reactjs - Fatal编程技术网

Javascript 如何在react服务器呈现的应用程序中访问公共url上的sitemap.xml

Javascript 如何在react服务器呈现的应用程序中访问公共url上的sitemap.xml,javascript,reactjs,Javascript,Reactjs,我正在开发一个使用服务器端渲染的react应用程序,我想在访问URL(例如localhost:3000/sitemap.xml)时查看sitemap.xml文件的内容。现在,我正在第三方库的帮助下生成站点地图文件,并在web包构建完成后将其放置在公用文件夹中 我的问题是在localhost:3000/sitemap.xml上找不到该文件。但是,我可以看到web包捆绑的其他文件,例如localhost:3000/main.css。我怎样才能达到预期的结果呢 站点地图生成器 import path

我正在开发一个使用服务器端渲染的react应用程序,我想在访问URL(例如localhost:3000/sitemap.xml)时查看sitemap.xml文件的内容。现在,我正在第三方库的帮助下生成站点地图文件,并在web包构建完成后将其放置在公用文件夹中

我的问题是在localhost:3000/sitemap.xml上找不到该文件。但是,我可以看到web包捆绑的其他文件,例如localhost:3000/main.css。我怎样才能达到预期的结果呢

站点地图生成器

import path from 'path'; //add path which will be needed for file write

const SitemapGenerator = require('sitemap-generator');

// create generator
const generator = SitemapGenerator('https://www.example.com', {
  stripQuerystring: false,
  filepath: path.resolve('./public', 'sitemap.xml')
});

// start the crawler
generator.start();

我通过将xml添加到服务器重写规则中解决了这个问题

它是

更新至