CorvidReference

QueryParams

An object used to manage the query segment of the current page's URL.

Table of Contents

FUNCTIONS

?
Perform actions on an object.
add( )Adds query parameters to the current page's URL.
remove( )Removes query parameters from the current page's URL.

add( )

Adds query parameters to the current page's URL.

Description

Adds one or more query parameters to the current page's URL.

If a specified key already exists as a query parameter, the newly specified value will overwrite the key's previous value.

Calling the add() function triggers the onChange() event handler if it has been registered.

Note

To retrieve the page's current query parameters, use the query property.

See Also

remove( )

Syntax

function add(toAdd: Object): void
PARAMETERS
?
Values that you pass to a function.
toAdd
Object

An object containing a key:value pair for each query parameter to add to the URL, where the object's keys are the query parameter keys and the object's values are the corresponding query parameter values.

Examples

Add query parameters to the URL

import wixLocation from 'wix-location';

// ...

wixLocation.queryParams.add({
  "key2": "value2new",
  "key3": "value3"
});

// URL before addition:
// www.mysite.com/page?key1=value1&key2=value2

// URL will look like:
// www.mysite.com/page?key1=value1&key2=value2new&key3=value3

remove( )

Removes query parameters from the current page's URL.

Description

Removes one or more query parameters to the current page's URL.

If a specified key does not exist as a query parameter, it is ignored.

Calling the remove() function triggers the onChange() event handler if it has been registered.

Note

To retrieve the page's current query parameters, use the query property.

See Also

add( )

Syntax

function remove(toRemove: Array<string>): void
PARAMETERS
?
Values that you pass to a function.
toRemove
Array<string>
List of keys to remove.

Examples

Remove query parameters from the URL

import wixLocation from 'wix-location';

// ...

wixLocation.queryParams.remove(["key1"]);

// URL before removal:
// www.mysite.com/page?key1=value1&key2=value2

// URL after removal:
// www.mysite.com/page?key2=value2