Modify a URL string's query args, by either adding a new one, updating an existing one, or removing an existing one.
Parameters:
Name | Type | Description |
---|---|---|
key | string | The URL param key. |
value | string | | The value for the key. Set to null to remove query arg. |
url | string | An URL string to manipulate. Defaults to current. |
- Since
- 1.0.0
- Source
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 );
}