From 61cbb07bd50978bd15badc12c341fd90e2e52e94 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 19 Jul 2022 12:33:53 -0700 Subject: [PATCH] Fix some broken stuff on the homepage contract search routing (#664) * Use Next router more appropriately * Replace instead of push when modifying search query params --- web/hooks/use-sort-and-query-params.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/hooks/use-sort-and-query-params.tsx b/web/hooks/use-sort-and-query-params.tsx index a2248c2e..5c9a247f 100644 --- a/web/hooks/use-sort-and-query-params.tsx +++ b/web/hooks/use-sort-and-query-params.tsx @@ -53,9 +53,12 @@ export function useInitialQueryAndSort(options?: { console.log('ready loading from storage ', sort ?? defaultSort) const localSort = getSavedSort() if (localSort) { - router.query.s = localSort // Use replace to not break navigating back. - router.replace(router, undefined, { shallow: true }) + router.replace( + { query: { ...router.query, s: localSort } }, + undefined, + { shallow: true } + ) } setInitialSort(localSort ?? defaultSort) } else { @@ -79,7 +82,9 @@ export function useUpdateQueryAndSort(props: { const setSort = (sort: Sort | undefined) => { if (sort !== router.query.s) { router.query.s = sort - router.push(router, undefined, { shallow: true }) + router.replace({ query: { ...router.query, s: sort } }, undefined, { + shallow: true, + }) if (shouldLoadFromStorage) { localStorage.setItem(MARKETS_SORT, sort || '') } @@ -97,7 +102,9 @@ export function useUpdateQueryAndSort(props: { } else { delete router.query.q } - router.push(router, undefined, { shallow: true }) + router.replace({ query: router.query }, undefined, { + shallow: true, + }) track('search', { query }) }, 500), [router]