Skip to content

Commit

Permalink
fix(useRouteQuery): allow setting multiple route queries in same tick (
Browse files Browse the repository at this point in the history
  • Loading branch information
wheatjs committed Jan 17, 2023
1 parent bb71173 commit 07c9517
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/router/useRouteQuery/index.ts
Expand Up @@ -3,6 +3,8 @@ import { computed, nextTick, unref } from 'vue-demi'
import { useRoute, useRouter } from 'vue-router'
import type { ReactiveRouteOptions } from '../_types'

let queue: Record<string, any> = {}

export function useRouteQuery(name: string): Ref<null | string | string[]>
export function useRouteQuery<T extends null | undefined | string | string[] = null | string | string[]>(name: string, defaultValue?: T, options?: ReactiveRouteOptions): Ref<T>
export function useRouteQuery<T extends string | string[]>(
Expand All @@ -24,8 +26,11 @@ export function useRouteQuery<T extends string | string[]>(
return data
},
set(v) {
queue[name] = v === defaultValue || v === null ? undefined : v

nextTick(() => {
router[unref(mode)]({ ...route, query: { ...route.query, [name]: v === defaultValue || v === null ? undefined : v } })
router[unref(mode)]({ ...route, query: { ...route.query, ...queue } })
nextTick(() => queue = {})
})
},
})
Expand Down

0 comments on commit 07c9517

Please sign in to comment.