UrlQueryParameterCollection class

Warning

This API is now deprecated.

Use the URLSearchParams browser API instead. The SharePoint Framework includes a polyfill for older browsers.

Provides features for storing and retrieving URL query parameters.

Remarks

The URL can be server-relative, and it can also be an empty or null string. The query parameters must start with "?" to indicate the first query parameter and use "&" for all subsequent parameters. The class also supports fragments.

Edge case behavior:

Empty value (www.example.com/?test=) stores key and empty value No equals in queryParam (www.example.com/?test) stores key and undefined value Empty queryParam (www.example.com/?&debug=on) stores undefined key and value Query param with only equals (www.example.com/?=&debug=on stores empty string key and value

Constructors

(constructor)(url)

Constructs a new instance of the UrlQueryParameterCollection class

Methods

getValue(param)

Returns the value of the first matching query parameter or undefined if the key doesn't exist.

getValues(param)

Returns the values of all of the matching query parameters or undefined if the key doesn't exist.

Constructor Details

(constructor)(url)

Constructs a new instance of the UrlQueryParameterCollection class

constructor(url: string);

Parameters

url

string

Method Details

getValue(param)

Returns the value of the first matching query parameter or undefined if the key doesn't exist.

getValue(param: string): string | undefined;

Parameters

param

string

the case insensitive key for the desired query parameter value.

Returns

string | undefined

Remarks

Examples:

this._queryParameterList = [
{key: TEST, value: done},
{key: DEBUG, value: false},
{key: TEST, value: notdone}]
  getValue('TEST') ---> 'done'
  getValue('debug')  ---> 'false'
  getValue('lost')  ---> undefined

getValues(param)

Returns the values of all of the matching query parameters or undefined if the key doesn't exist.

getValues(param: string): (string | undefined)[] | undefined;

Parameters

param

string

the case insensitive key for the desired query parameter value.

Returns

(string | undefined)[] | undefined

Remarks

Examples:

this._queryParameterList = [
{key: TEST, value: done},
{key: DEBUG, value: false},
{key: TEST, value: notdone}]
  getValues('TEST') ---> ['done', 'notdone']
  getValues('debug')  ---> ['false']
  getValues('lost')  ---> undefined