remove( )
Removes query parameters from the current page's URL.
Description
Removes one or more query parameters to the current page's URL.
The remove()
function can only be used when browser
rendering happens,
meaning you can only use it in frontend code after the page is ready.
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.
Syntax
function remove(toRemove: Array<string>): void
remove Parameters
NAME
TYPE
DESCRIPTION
List of keys to remove.
Returns
This function does not return anything.
Return Type:
Related Content:
Was this helpful?
1import wixLocationFrontend from 'wix-location-frontend';23// ...45wixLocationFrontend.queryParams.remove(["key1"]);67// URL before removal:8// www.mysite.com/page?key1=value1&key2=value2910// URL after removal:11// www.mysite.com/page?key2=value2
Note: It's easiest to test this example in a published version of your site. If you test using preview, you will see a lot of extra query parameters from the Editor URL. You can test out the code in our example template.
1import wixLocationFrontend from 'wix-location-frontend';23$w.onReady(function () {4 $w("#addButton").onClick((event) => {5 const key = $w('#addKey').value;6 const value = $w('#addValue').value;7 if (key && value) {8 const toAdd = { [key]: value };9 wixLocationFrontend.queryParams.add(toAdd);10 $w('#addKey').value = undefined;11 $w('#addValue').value = undefined;12 }13 });1415 $w("#removeButton").onClick((event) => {16 const paramToRemove = [$w('#removeKey').value];17 wixLocationFrontend.queryParams.remove(paramToRemove);18 $w('#removeKey').value = undefined;19 });2021 $w("#getButton").onClick((event) => {22 const query = wixLocationFrontend.query;23 if (query) {24 $w('#getText').value = JSON.stringify(query, null, 2);25 }26 });27});