react change url params code example

Example 1: append a query string to the url react

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

Example 2: history push search params

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

Example 3: react change url params

if (history.pushState) {
    var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?myNewUrlQuery=1';
    window.history.pushState({path:newurl},'',newurl);
}