Skip to content

Commit

Permalink
fix: include route.path in query observer
Browse files Browse the repository at this point in the history
  • Loading branch information
cuebit committed Feb 3, 2025
1 parent 709411e commit 21d272a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/composables/Url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isEqual from 'lodash-es/isEqual'
import { type MaybeRef, nextTick, unref, watch } from 'vue'
import { type MaybeRef, computed, nextTick, unref, watch } from 'vue'
import { type LocationQuery, useRoute, useRouter } from 'vue-router'

export interface UseUrlQuerySyncOptions {
Expand All @@ -21,13 +21,22 @@ export function useUrlQuerySync(
const route = useRoute()
const router = useRouter()

const routeQuery = computed(() => ({
path: route.path,
query: route.query
}))

const flattenedDefaultState = flattenObject(unref(state))

let isSyncing = false

watch(
() => route.query,
async () => {
routeQuery,
async (to, from) => {
if (from && from.path !== to.path) {
return
}

if (!isSyncing) {
isSyncing = true
await setState()
Expand Down

0 comments on commit 21d272a

Please sign in to comment.