I have a url like this:
The "1" is the user id as parameter, how can I get it in react js?
I have a url like this:
The "1" is the user id as parameter, how can I get it in react js?
If router is like this
<Route exact path="/category/:id" component={ProductList}/>
Access like this
this.props.match.params.id
for your reference URL Parameters with React Router
FWIW it's much easier now using hooks in React Router DOM v5 (link)
In Router define routes as normal:
<Route path="/users/:id" ...
And in the Component, simply deconstruct the useParams hook:
const { id } = useParams();
It's that simple!
==============================Using component==================
<Route path="/users/:id" component={UserPage}/>
this.props.match.params.id
===============================Using render====================
<Route path="/users/:id" render={(props) => <UserPage {...props} />}/>
this.props.match.params.id
For Query Parameter: https://github.com/sindresorhus/query-string
this.props.match.params.parm_name