I am using versions
"react": "^0.13.3",
"react-router": "^0.13.3"
i want to receive the params in which it navigate
1)Navigation done properly
2)what when i try to use this.props.query.id
for receiving arguments it show undefined
.
To get path params in React Router, we can use the useParams hook. We create the Child component that calls the useParams hook to return an object with the route params in the URL. And we render the value of the id param on the page. In App , we have 2 links that goes to routes with different id param values.
upgrade to react-router v4 and ;
Use this instead:
this.props.location.search
if you have a URL like mysite.com/user/tweets?filter=top&origin=im
Doing:
console.log(this.props.location.search); //yields "?filter=top&origin=im"
Thus to get the value of "filter" or "origin", you need to use a package for parsing query strings because react-router doesn’t come with built-in support for parsing query strings. E.g. using 'query-string' library on NPM you can do:
import queryString from 'query-string';
const UrlQueryStrings = this.props.location.search;
const queryValues = queryString(UrlQueryStrings);
console.log(queryValues.filter); // Gives "top"
console.log(queryValues.origin); // Gives "im"
Use this:
this.props.location.query.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With