import { parse , stringify } from 'query-string' ; import { History , Location } from 'history' ; import { url } from '../../common' ; export function removeQueryParam ( history , param , replace = true ) { const oldLocation = history . location ; const search = ( oldLocation . search || '' ) . replace ( /^\?/ , '' ) ; const query = parse ( search , { sort : false } ) ; delete query [ param ] ; const newSearch = stringify ( url . encodeQuery ( query ) , { sort : false , encode : false } ) ; const newLocation = { ... oldLocation , search : newSearch , } ; if ( replace ) { history . replace ( newLocation ) ; } else { history . push ( newLocation ) ; } }