Skip to content
On this page

useRouteParams

Category
Export Size
454 B
Package
@vueuse/router
Last Changed
4 months ago

Shorthand for a reactive route.params. Available in the @vueuse/router add-on.

Usage

ts
import { useRouteParams } from '@vueuse/router'

const userId = useRouteParams('userId')

const userId = useRouteParams('userId', '-1') // or with a default value

console.log(userId.value) // route.params.userId
userId.value = '100' // router.replace({ params: { userId: '100' } })
import { useRouteParams } from '@vueuse/router'

const userId = useRouteParams('userId')

const userId = useRouteParams('userId', '-1') // or with a default value

console.log(userId.value) // route.params.userId
userId.value = '100' // router.replace({ params: { userId: '100' } })

Type Declarations

typescript
export declare function useRouteParams(
  name: string
): Ref<null | string | string[]>
export declare function useRouteParams<
  T extends null | undefined | string | string[] = null | string | string[]
>(name: string, defaultValue?: T, options?: ReactiveRouteOptions): Ref<T>
export declare function useRouteParams(
  name: string
): Ref<null | string | string[]>
export declare function useRouteParams<
  T extends null | undefined | string | string[] = null | string | string[]
>(name: string, defaultValue?: T, options?: ReactiveRouteOptions): Ref<T>

Source

SourceDocs

Contributors

Dvir Hazout
Curt Grimes
DevilTea

Changelog

v9.4.0 on 10/25/2022
be36a - fix(useRouteHash, useRouteParams, useRouteQuery): override only selected route param (#2350)
v8.9.0 on 7/6/2022
ece3d - feat: new function (#1173)

Released under the MIT License.