useRouteQuery
Shorthand for a reactive route.query
. Available in the @vueuse/router add-on.
Usage
ts
import { useRouteQuery } from '@vueuse/router'
const search = useRouteQuery('search')
const search = useRouteQuery('search', 'foo') // or with a default value
const page = useRouteQuery('page', '1', { transform: Number }) // or transforming value
console.log(search.value) // route.query.search
search.value = 'foobar' // router.replace({ query: { search: 'foobar' } })
Type Declarations
typescript
export declare function useRouteQuery(
name: string,
): Ref<undefined | null | string | string[]>
export declare function useRouteQuery<
T extends RouteQueryValueRaw = RouteQueryValueRaw,
K = T,
>(
name: string,
defaultValue?: MaybeRefOrGetter<T>,
options?: ReactiveRouteOptionsWithTransform<T, K>,
): Ref<K>
Source
Contributors
Changelog
v12.8.0
on v12.3.0
on 59f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.1.0
on 23fdb
- fix(useRouteParams,useRouteQuery): set route param/query to undefined when defaultValue is ref or getter (#3977)v11.3.0
on 44772
- fix(useRouteParams, useRouteQuery): effect triggers twice with object getter as watch source (#4283)965bf
- fix(useRouteHash, useRouteParams, useRouteQuery): fix effect triggering multiple times (#4113)v10.8.0
on c44fe
- fix(useRouteParams,useRouteQuery): set route param/query to undefined when null or defaultValue (#3583)v10.6.0
on v10.3.0
on 0d02f
- fix(router): improves router functions: synchronize values, adds tests, and optimize performance (#3184)v10.2.0
on