How to get query parameters in React Router v4

  • Use the "this.props.location.query" object
  • Use the "this.props.location.search" property
  • Use the "this.props.params" object
  • Use the "this.props.query" object
In React Router v4, you can get query parameters by using the "location.search" property of the current location object. This property contains the query string of the URL, including the "?" character and the parameter keys and values. To parse the query string, you can use a library like "query-string" or "URLSearchParams". For example: const queryParams = new URLSearchParams(this.props.location.search); const foo = queryParams.get('foo');.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *