t-comm
Version:
专业、稳定、纯粹的工具库
37 lines (36 loc) • 1.62 kB
TypeScript
/**
* @export removeUrlParams
* @description 移除参数
* @param {string} url 地址
* @param {string} removeKeyArr 待移除的参数名集合
* @returns 重新拼接的地址
* @example
* // 地址是 hash 模式参数
* removeUrlParams('http://www.test.com/#/detail?a=1&b=2&c=3', ['a', 'b']);
* // => 'http://www.test.com/#/detail?c=3'
* @example
* // 地址 history 模式参数并存
* removeUrlParams('http://www.test.com?a=1&b=2&c=3', ['a', 'b']);
* // => 'http://www.test.com?c=3'
* @example
* // 地址 history 模式参数并存 + 强制 history 模式返回
* removeUrlParams('http://www.test.com?a=1&b=2&c=3', ['a', 'b'], true);
* // => 'http://www.test.com?c=3'
* @example
* // 全部参数移除完,返回不带 query 的地址
* removeUrlParams('http://www.test.com?a=1&b=2&c=3', ['a', 'c', 'b'], true);
* // => 'http://www.test.com'
* @example
* // hash 模式下 query 全部移除,会保留末尾的 ?
* removeUrlParams('http://www.test.com?a=1&b=2&c=3#/detail?d=4', ['a', 'b', 'c', 'd']);
* // => 'http://www.test.com/#/detail?'
* @example
* // hash 模式和 history 模式参数并存
* removeUrlParams('http://www.test.com?a=1&b=2&c=3#/detail?d=4', ['a', 'd']);
* // => 'http://www.test.com/#/detail?b=2&c=3'
* @example
* // 地址是 hash 模式和 history 模式参数并存,且是多个参数
* removeUrlParams('http://www.test.com?d=4&f=6#/detail?a=1&b=2&c=3', ['a', 'd']);
* // => 'http://www.test.com/#/detail?f=6&b=2&c=3'
*/
export declare function removeUrlParams(url: string | undefined, removeKeyArr: string[], forceHistoryMode?: boolean): string;