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
This commit is contained in:
parent
12567074cc
commit
61cbb07bd5
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue
Block a user