Uri class
表示 URI 的類別,並允許剖析/取得和設定個別元件
建構函式
Uri(string, IUri |
建立新的 URI。 |
屬性
absolute |
設定此 URI 的絕對 URI 字串。 取代所有現有的值 |
hash |
URI 的哈希字串 |
host | URI 主機名稱 (不包含埠或設定) |
no |
如果為 true,請勿在配置之後發出 “/”分隔符:針對mailto等設定設定為 true (例如 mailto:foo@bar) |
path | URI 的相對路徑 |
port | URL 中提供的 URI 埠號碼。 如果 url 中排除 ,則為 0 (例如設定的預設埠)。 |
query |
uri 中的查詢參數陣列 |
query |
設定此 URI 的查詢字串。 取代現有的值 |
scheme | URI 配置,例如 HTTP 或 HTTPs |
方法
add |
將查詢字串參數新增至目前的 URI |
add |
將查詢字串參數新增至目前的 URI |
get |
取得有效的埠號碼,如果省略指定的配置,則傳回預設埠號碼。 |
get |
使用指定的索引鍵取得查詢參數的值 |
remove |
拿掉查詢字串參數 |
Uri(string, IUriParseOptions)
建立新的 URI。
new Uri(uri?: string, options?: IUriParseOptions)
參數
- uri
-
string
選擇性 URI 字串,以填入值
- options
- IUriParseOptions
剖析 URI 字串的選項
absoluteUri
設定此 URI 的絕對 URI 字串。 取代所有現有的值
absoluteUri: string
屬性值
string
hashString
URI 的哈希字串
hashString: string
屬性值
string
host
URI 主機名稱 (不包含埠或設定)
host: string
屬性值
string
noSchemeSeparator
如果為 true,請勿在配置之後發出 “/”分隔符:針對mailto等設定設定為 true (例如 mailto:foo@bar)
noSchemeSeparator: boolean
屬性值
boolean
path
URI 的相對路徑
path: string
屬性值
string
port
URL 中提供的 URI 埠號碼。 如果 url 中排除 ,則為 0 (例如設定的預設埠)。
port: number
屬性值
number
queryParameters
queryString
設定此 URI 的查詢字串。 取代現有的值
queryString: string
屬性值
string
scheme
URI 配置,例如 HTTP 或 HTTPs
scheme: string
屬性值
string
addQueryParam(string, null | string, boolean)
將查詢字串參數新增至目前的 URI
function addQueryParam(name: string, value: null | string, replaceExisting?: boolean)
參數
- name
-
string
查詢參數名稱
- value
-
null | string
Query 參數值
- replaceExisting
-
boolean
如果為 true,請以相同名稱取代所有現有的參數
addQueryParams({[key: string]: QueryParameterValueType}, boolean, string)
將查詢字串參數新增至目前的 URI
function addQueryParams(parameters: {[key: string]: QueryParameterValueType}, replaceExisting?: boolean, keyPrefix?: string)
參數
- parameters
-
{[key: string]: QueryParameterValueType}
要新增的查詢參數
- replaceExisting
-
boolean
如果為 true,請以相同名稱取代所有現有的參數
- keyPrefix
-
string
如果指定,則為所有查詢參數索引鍵前面要加上的值
getEffectivePort()
取得有效的埠號碼,如果省略指定的配置,則傳回預設埠號碼。
function getEffectivePort(): number
傳回
number
getQueryParam(string)
使用指定的索引鍵取得查詢參數的值
function getQueryParam(name: string): undefined | null | string
參數
- name
-
string
查詢參數名稱
傳回
undefined | null | string
removeQueryParam(string)
拿掉查詢字串參數
function removeQueryParam(name: string)
參數
- name
-
string
查詢參數名稱