useRouteParams ​
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
const userId = useRouteParams('page', '1', { transform: Number }) // or transforming 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 RouteParamValueRaw = RouteParamValueRaw,
K = T,
>(
name: string,
defaultValue?: MaybeRefOrGetter<T>,
options?: ReactiveRouteOptionsWithTransform<T, K>,
): Ref<K>
Source ​
Contributors ​
Antério Vieira
Anthony Fu
Guillaume Chau
jack-allocate
Anthony Fu
Lindsay Gaines
huiliangShen
Manoah Tervoort
Shean de Montigny-Desautels
Eduardo Wesley
Dvir Hazout
Curt Grimes
DevilTea
Changelog ​
Pending for release...
44772
- fix(useRouteParams, useRouteQuery): effect triggers twice with object getter as watch source (#4283)v11.0.0-beta.3
on 8/14/2024965bf
- fix(useRouteHash, useRouteParams, useRouteQuery): fix effect triggering multiple times (#4113)v10.10.0
on 5/27/2024v10.8.0
on 2/20/2024c44fe
- fix(useRouteParams,useRouteQuery): set route param/query to undefined when null or defaultValue (#3583)v10.6.0
on 11/9/2023v10.3.0
on 7/30/20230d02f
- fix(router): improves router functions: synchronize values, adds tests, and optimize performance (#3184)v10.2.0
on 6/16/2023v10.0.0-beta.4
on 4/13/2023v9.4.0
on 10/25/2022