How to get the url params from a route in React
How to get the url params from a route in React
In this post let's see how to get the current url params inside a react component
Getting the URL Params using React Router
consider you have a Route as below
<Route path="/posts/:id" component={Posts} />
Now we can access the id
param inside a component as below
import React from 'react'
const Posts = ({match}) => {
const id = match.params.id;
return (
<h1>{id}</h1>
)
}
That's it Guys give it a 👍 if you found it useful.