t-comm
Version:
专业、稳定、纯粹的工具库
28 lines (27 loc) • 1.25 kB
TypeScript
/**
* 拼接额外参数
* @param {string} url 地址
* @param {string} removeKeyArr 待添加的参数对象
* @returns 重新拼接的地址
* @example
* // 地址是 hash 模式参数
* extendUrlParams('http://www.test.com/#/detail?a=1&b=2&c=3', { d: 4 });
* // => 'http://www.test.com/#/detail?a=1&b=2&c=3&d=4'
* @example
* // 地址 history 模式参数并存
* extendUrlParams('http://www.test.com?a=1&b=2&c=3', { d: 4 });
* // => 'http://www.test.com/?a=1&b=2&c=3&d=4'
* @example
* // 地址 history 模式参数并存 + 强制 history 模式返回
* extendUrlParams('http://www.test.com?a=1&b=2&c=3', { d: 4 }, true);
* // => 'http://www.test.com/?a=1&b=2&c=3&d=4'
* @example
* // hash 模式和 history 模式参数并存
* extendUrlParams('http://www.test.com?a=1&b=2&c=3#/detail?d=4', { e: 5 });
* // => 'http://www.test.com/#/detail?a=1&b=2&c=3&d=4&e=5'
* @example
* // 地址是 hash 模式和 history 模式参数并存,且是多个参数
* extendUrlParams('http://www.test.com?d=4&f=6#/detail?a=1&b=2&c=3', { e: 5, g: 7 });
* // => 'http://www.test.com/#/detail?d=4&f=6&a=1&b=2&c=3&e=5&g=7'
*/
export declare function extendUrlParams(url?: string, extParamsObj?: {}, forceHistoryMode?: boolean): string;