Do experimental.paramParsers affect route matching? /c still matches [context=context].vue
#782
-
|
vue-router: I created a custom param parser at export const allowedContexts = ['a', 'b'] as const
export type Context = (typeof allowedContexts)[number]
export function isContext(value: unknown): value is Context {
return !!allowedContexts.find((allowedContext) => allowedContext === value)
}
export const parser = {
get(value: unknown): Context {
if (isContext(value)) {
return value
}
throw new Error(
`Invalid context: "${value}". Expected one of: ${allowedContexts.join(', ')}`
)
},
set(value: unknown): Context {
if (isContext(value)) {
return value
}
throw new Error(
`Invalid context: "${value}". Expected one of: ${allowedContexts.join(', ')}`
)
},
}My page file is: This gives me correct typing (
Questions
definePage({ path: '/:context(a|b)' })...but now allowed values exist in two places (parser file + path in definePage). Goal
What’s the intended pattern here? Thanks for any clarification! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
|
The examples that can be found on param parser |
Beta Was this translation helpful? Give feedback.
The examples that can be found on param parser
miss()instead of just a regular error, could that be the difference? https://github.com/vuejs/router/blob/main/packages/router/src/experimental/route-resolver/matchers/errors.ts