I'm using a simple router in React
<Router>
<div>
<Switch>
<Route path="/" component={ Home } exact />
<Route path="/contact" component={ Contact } />
<Route path="/:slug" component={ Post } />
</Switch>
</div>
</Router>
I'm pulling posts from a blog using REST and have a router component named Post for single blog posts. Any Route that doesn't match with home
or contact
, uses the post
component.
How can I get or pass the route slug/url segment in the Post component? For example if the url segment/slug is /some-blog-post-title
, I want to retrieve it, preferably using a React Router function/method if it exists.