我在React 18.2.0中有SPA,我想生成sitemap.xml。我尝试过 React Router Sitemap 包,但它不适用于最新版本的 React。我还希望它根据我的routes.js 文件生成所有子页面。
const routes = [
{
path: "/",
component: Home
},
{
path: "/sortiment",
component: Sortiment
},
{
path: "/kontakt",
component: Contact
},
{
path: "/aktualne",
component: News
},
{
path: "/o-nas",
component: About
},
{
path: "/nase-sluzby",
component: Services
},
{
path: "/sortiment/:categoryName",
component: CategoryPage
},
];
我也尝试安装React Router Sitemap Generator,结果是一样的。
这里是您的路线的 xml 站点地图。
只需为每个
url
添加更多
categoryName
changefreq
可以是这些值中的任何一个
daily
weekly
monthly
yearly
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://localhost/</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/sortiment</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/kontakt</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/aktualne</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/o-nas</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/nase-sluzby</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>https://localhost/sortiment/:categoryName</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
</urlset>