【发布时间】:2022-07-04 17:55:39
【问题描述】:
我正在尝试使用 react-router-sitemap 为我们的站点生成 sitemap.xml。但是,输出文件只列出了 URL,没有列出任何路由。
输出文件-
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url> <loc>http://localhost:3000/</loc> </url>
</urlset>
我的脚本:
require('babel-register');
const router = "./components/main/contentArea.tsx"
const sitemap = require('react-router-sitemap').default;
(
new sitemap(router)
.build('http://localhost:3000/')
.save('public/sitemap.xml')
);
我们的路由器看起来像这样(我们使用 react-router-dom,但也使用 react-router 进行了测试,输出仍然相同)
<Switch>
<Route exact path="/" component={Dashboard} />
<Route exact path="/admin/users/users" component={Users} />
</Switch>
我已经尝试了一段时间,但我很困惑为什么这种方法不起作用。任何帮助或想法将不胜感激。谢谢。
【问题讨论】:
标签: reactjs react-router react-router-dom