src/updateUrlQuery.js
function multiUpdateInLocation(queryReplacements, location) {
  location = getLocation(location);

  // if a query is there, use it, otherwise parse the search string
  const currQuery = location.query || parseQueryString(location.search);

  const newQuery = {
    ...currQuery,
    ...queryReplacements,
  };

  // remove if it is nully or an empty string when encoded
  Object.keys(queryReplacements).forEach(queryParam => {
    const encodedValue = queryReplacements[queryParam];
    if (encodedValue == null || encodedValue === '') {
      delete newQuery[queryParam];
    }
  });

  const newLocation = mergeLocationQueryOrSearch(location, newQuery);

  // remove the key from the location
  delete newLocation.key;

  return newLocation;
}
function multiUpdateInLocation(queryReplacements, location) {
  location = getLocation(location);

  // if a query is there, use it, otherwise parse the search string
  const currQuery = location.query || parseQueryString(location.search);

  const newQuery = {
    ...currQuery,
    ...queryReplacements,
  };

  // remove if it is nully or an empty string when encoded
  Object.keys(queryReplacements).forEach(queryParam => {
    const encodedValue = queryReplacements[queryParam];
    if (encodedValue == null || encodedValue === '') {
      delete newQuery[queryParam];
    }
  });

  const newLocation = mergeLocationQueryOrSearch(location, newQuery);

  // remove the key from the location
  delete newLocation.key;

  return newLocation;
}
function multiUpdateInLocation ( queryReplacements , location ) { location = getLocation ( location ) ; // if a query is there, use it, otherwise parse the search string const currQuery = location . query || parseQueryString ( location . search ) ; const newQuery = { ... currQuery , ... queryReplacements , } ; // remove if it is nully or an empty string when encoded Object . keys ( queryReplacements ) . forEach ( queryParam => { const encodedValue = queryReplacements [ queryParam ] ; if ( encodedValue == null || encodedValue === '' ) { delete newQuery [ queryParam ] ; } } ) ; const newLocation = mergeLocationQueryOrSearch ( location , newQuery ) ; // remove the key from the location delete newLocation . key ; return newLocation ; }
Update multiple parts of the location at once
Update multiple parts of the location at once