Files
new-phone-who-dis/phone/src/common/utils/addQueryToLocation.ts
T
2021-03-02 20:45:41 +01:00

20 lines
392 B
TypeScript

import qs from 'qs';
import url from 'parse-url';
interface IRouterLocation {
pathname: string;
search: string;
}
export const addQueryToLocation = (
{ pathname = '', search = '' }: Record<string, unknown> & IRouterLocation,
key = '',
value = '',
) => {
const { query } = url(pathname + search);
return `${pathname}?${qs.stringify({
...query,
[key]: value,
})}`;
};