Modify a URL string's query args, by either adding a new one, updating an existing one, or removing an existing one.

Parameters:
NameTypeDescription
keystring

The URL param key.

valuestring | null

The value for the key. Set to null to remove query arg.

urlstring

An URL string to manipulate. Defaults to current.

Since
  • 1.0.0
Returns:

Returns the updated URL.

Type: 
string
Example
import { updateQueryVar } from "@gravityforms/utils";

function Example() {
  const url    = 'http://domain.com/?query1=val1';
	 const newUrl = updateQueryVar( 'query2', 'val2', url );
}