UNPKG

t-comm

Version:

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

28 lines (27 loc) 1.34 kB
/** * 根据传入的参数,移除原来的所有参数,根据传入的 keepParamsObj 进行重新拼接地址,以 hash 模式返回 * @param {string} url 地址 * @param {object} keepParamsObj 参数对象 * @returns 只有传入参数的地址 * @example * // 地址是 hash 模式参数 * formatUrlParams('http://www.test.com/#/detail?a=1&b=2&c=3', { d: 4 }); * // => 'http://www.test.com/#/detail?d=4' * @example * // 地址 history 模式参数并存(默认仍以 hash 模式返回) * formatUrlParams('http://www.test.com?a=1&b=2&c=3', { d: 4 }); * // => 'http://www.test.com/?d=4' * @example * // hash 模式和 history 模式参数并存 * formatUrlParams('http://www.test.com?a=1&b=2&c=3#/detail?d=4', { e: 5 }); * // => 'http://www.test.com/#/detail?e=5' * @example * // 地址是 hash 模式和 history 模式参数并存,且是多个参数 * formatUrlParams('http://www.test.com?d=4&f=6#/detail?a=1&b=2&c=3', { e: 5, g: 7 }); * // => 'http://www.test.com/#/detail?e=5&g=7' * @example * // 子工程是 history 模式(forceHistoryMode = true) * formatUrlParams('http://www.test.com?a=1&b=2&c=3', { d: 4 }, true); * // => 'http://www.test.com/?d=4' */ export declare function formatUrlParams(url?: string, keepParamsObj?: Record<string, string | number>, forceHistoryMode?: boolean): string;