admin管理员组文章数量:1287856
I am using react-router-dom for routing in my react app, There are nearly 5000 pages (which are generated dynamically based on API), now I don't know how can I generate a sitemap for these dynamic pages
Piece of code from my Routes ponent
<Route
path={process.env.PUBLIC_URL + '/genres/:name'}
exact
ponent={MovieGenre}
/>
<Route
path={process.env.PUBLIC_URL + '/discover/:name'}
exact
ponent={DiscoverMovies}
/>
<Route
path={process.env.PUBLIC_URL + '/find/:query'}
exact
ponent={SearchPage}
/>
<Route
path={process.env.PUBLIC_URL + '/moviesdetail/:id'}
exact
ponent={MovieScrees}
/>
I am using react-router-dom for routing in my react app, There are nearly 5000 pages (which are generated dynamically based on API), now I don't know how can I generate a sitemap for these dynamic pages
Piece of code from my Routes ponent
<Route
path={process.env.PUBLIC_URL + '/genres/:name'}
exact
ponent={MovieGenre}
/>
<Route
path={process.env.PUBLIC_URL + '/discover/:name'}
exact
ponent={DiscoverMovies}
/>
<Route
path={process.env.PUBLIC_URL + '/find/:query'}
exact
ponent={SearchPage}
/>
<Route
path={process.env.PUBLIC_URL + '/moviesdetail/:id'}
exact
ponent={MovieScrees}
/>
Share
Improve this question
edited Jun 24, 2021 at 5:10
thelovekesh
1,4521 gold badge9 silver badges22 bronze badges
asked Jun 24, 2021 at 5:06
Suhail KakarSuhail Kakar
3261 gold badge4 silver badges17 bronze badges
0
2 Answers
Reset to default 6You can use react-router-sitemap
to generate a sitemap.xml file for your React application.
Package:
npm i --save react-router-sitemap
Package link - https://www.npmjs./package/react-router-sitemap
If you want to implement this in your app then grab all code from here
When we say dynamic routing, we mean routing that takes place as your app is rendering, not in a configuration or convention outside of a running app. that means almost everything is a ponent in react-router.
- First, grab yourself a Router ponent for the environment you’re targeting and render it at the top of your app.
- Next, grab the link ponent to link to a new location:
- Finally, render a Route to show some UI when the user visits /dashboard.
// react-dom (what we'll use here)
import { BrowserRouter } from "react-router-dom";
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
el
);
Next, grab the link ponent to link to a new location:const App = () => (
<div>
<nav>
<Link to="/dashboard">Dashboard</Link>
</nav>
</div>
);
Finally, render a Route to show some UI when the user visits /dashboard.const App = () => (
<div>
<nav>
<Link to="/dashboard">Dashboard</Link>
</nav>
<div>
<Route path="/dashboard" ponent={Dashboard} />
</div>
</div>
);
**In this blog author explained in an easy waylink **
Solution 2
There are some npm packages which will handle sitemap
- https://www.npmjs./package/react-router-sitemap
- https://www.npmjs./package/react-router-sitemap-generator
- How to generate sitemap with react router
本文标签: javascriptHow to generate a sitemap dynamically in React JSStack Overflow
版权声明:本文标题:javascript - How to generate a sitemap dynamically in React JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741329049a2372663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论