How to define types for RouterLink props? #66
-
Error:
|
Beta Was this translation helpful? Give feedback.
Answered by
posva
Sep 22, 2022
Replies: 2 comments 2 replies
-
I hope this snippet will help someone import { RouteNamedMap } from 'vue-router/auto/routes'
export type TypedRouteLocation<T = keyof RouteNamedMap> =
T extends infer R extends keyof RouteNamedMap
? Record<never, never> extends RouteNamedMap[R]['params']
? {
name: R
}
: {
name: R
params: RouteNamedMap[R]['params']
}
: never <RouterLink :to="route">
Link
</RouterLink> const route = computed<TypedRouteLocation>(() => ({
name: '/somePath',
params: { uuid }
})) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I implemented a type that can be used directly at 731e9dd import { type RouteLocationRaw } from 'vue-router/auto'
const to = computed<RouteLocationRaw>(...) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
grindpride
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I implemented a type that can be used directly at 731e9dd