UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

28 lines (27 loc) 1.21 kB
/** * 除保留参数外,一律移除 * @param {string} url 地址 * @param {string} removeKeyArr 待保留的参数名集合 * @returns 重新拼接的地址 * @example * // 地址是 hash 模式参数 * keepUrlParams('http://www.test.com/#/detail?a=1&b=2&c=3', ['a', 'b']); * // => 'http://www.test.com/#/detail?a=1&b=2' * @example * // 地址 history 模式参数并存 * keepUrlParams('http://www.test.com?a=1&b=2&c=3', ['a', 'b']); * // => 'http://www.test.com/?a=1&b=2' * @example * // 地址 history 模式参数并存 + 强制 history 模式返回 * keepUrlParams('http://www.test.com?a=1&b=2&c=3', ['a', 'b'], true); * // => 'http://www.test.com/?a=1&b=2' * @example * // hash 模式和 history 模式参数并存 * keepUrlParams('http://www.test.com?a=1&b=2&c=3#/detail?d=4', ['a', 'd']); * // => 'http://www.test.com/#/detail?a=1&d=4' * @example * // 地址是 hash 模式和 history 模式参数并存,且是多个参数 * keepUrlParams('http://www.test.com?d=4&f=6#/detail?a=1&b=2&c=3', ['a', 'd']); * // => 'http://www.test.com/#/detail?d=4&a=1' */ export declare function keepUrlParams(url: string | undefined, keepKeyArr: string[], forceHistoryMode?: boolean): string;