Skip to content
On this page

useRouteQuery

Category
Export Size
461 B
Package
@vueuse/router
Last Changed
3 weeks ago

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

console.log(search.value) // route.query.search
search.value = 'foobar' // router.replace({ query: { search: 'foobar' } })
import { useRouteQuery } from '@vueuse/router'

const search = useRouteQuery('search')

const search = useRouteQuery('search', 'foo') // or with a default 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<null | string | string[]>
export declare function useRouteQuery<
  T extends null | undefined | string | string[] = null | string | string[]
>(name: string, defaultValue?: T, options?: ReactiveRouteOptions): Ref<T>
export declare function useRouteQuery(
  name: string
): Ref<null | string | string[]>
export declare function useRouteQuery<
  T extends null | undefined | string | string[] = null | string | string[]
>(name: string, defaultValue?: T, options?: ReactiveRouteOptions): Ref<T>

Source

SourceDocs

Contributors

Anthony Fu
wheat
Dvir Hazout
Curt Grimes
Sacha STAFYNIAK
reslear
Marshall Thompson

Changelog

v9.11.0 on 1/17/2023
07c95 - fix: allow setting multiple route queries in same tick (#2646)
v9.4.0 on 10/25/2022
be36a - fix(useRouteHash, useRouteParams, useRouteQuery): override only selected route param (#2350)
v8.2.6 on 4/14/2022
c1459 - fix: unset route query on default value (#1490)

Released under the MIT License.