route.params[param] incorrectly shows param does not exist #176
-
I have two routes defined, one with route parameters, and one without: declare module 'vue-router/auto/routes' {
export interface RouteNamedMap {
'/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
'/catalog/categories/': RouteRecordInfo<'/catalog/categories/', '/catalog/categories', Record<never, never>, Record<never, never>>,
'/catalog/categories/[id]': RouteRecordInfo<'/catalog/categories/[id]', '/catalog/categories/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
}
} In my component I am trying to access the current route's const route = useRoute()
const id = route.params.id but I get the following typescript error:
Which is happening because the resulting union of I'm currently working around this by doing the following which is not ideal because I basically throw away any type safety const route = useRoute()
const id = (route.params as any).id |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Try passing a string and trigger autocomplete to useRoute(‘’), select the correct route and you’re good to go! |
Beta Was this translation helpful? Give feedback.
Try passing a string and trigger autocomplete to useRoute(‘’), select the correct route and you’re good to go!