react set query params code example

Example 1: append a query string to the url react

history.push({
  pathname: '/dresses',
  search: '?color=blue'
})

Example 2: use query params react

const query = new URLSearchParams(this.props.location.search);

const token = query.get('token')
console.log(token)//123

Example 3: get query params react

new URLSearchParams(this.props.location.search).get("your_query_param_key")

Example 4: history push search params

this.props.history.push({
    pathname: '/client',
    search: "?" + new URLSearchParams({clientId: clientId}).toString()
})