mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-27 18:14:54 +00:00
21 lines
627 B
TypeScript
21 lines
627 B
TypeScript
import * as QueryString from 'query-string';
|
|
import { Location, History } from 'history';
|
|
|
|
type QueryParam = {
|
|
[key: string]: string | undefined;
|
|
};
|
|
|
|
export default function updateQueryParams(newParams: QueryParam, location: Location, history: History) {
|
|
const parsedParams = QueryString.parse(location.search, { arrayFormat: 'comma' });
|
|
const updatedParams = {
|
|
...parsedParams,
|
|
...newParams,
|
|
};
|
|
const stringifiedParams = QueryString.stringify(updatedParams, { arrayFormat: 'comma' });
|
|
|
|
history.replace({
|
|
pathname: location.pathname,
|
|
search: stringifiedParams,
|
|
});
|
|
}
|