Generate sitemap.xml
from react-router.
yarn add --dev react-router-sitemap-generator
yarn add --dev @babel/node @babel/preset-env @babel/preset-react
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
// sitemap.js
import Generator from 'react-router-sitemap-generator';
import Router from './component/Router'; //import your react router component
const generator = new Generator(
'https://react-router-sitemap-generator.com',
Router(),
{
lastmod: new Date().toISOString().slice(0, 10),
changefreq: 'monthly',
priority: 0.8,
}
);
generator.save('public/sitemap.xml');
yarn run babel-node sitemap.js
- Support nested routes