Delete query param when empty

This commit is contained in:
James Grugett 2022-07-29 17:37:34 -07:00
parent be01a15230
commit d6cf4332da

View File

@ -104,7 +104,9 @@ export function useQueryAndSortParams(options?: {
const pushQuery = useMemo( const pushQuery = useMemo(
() => () =>
debounce((query: string | undefined) => { debounce((query: string | undefined) => {
router.replace({ query: { ...router.query, q: query } }, undefined, { const queryObj = { ...router.query, q: query || undefined }
if (!query) delete queryObj.q
router.replace({ query: queryObj }, undefined, {
shallow: true, shallow: true,
}) })
}, 100), }, 100),