H3 · H30009
Use getValidatedRouterParams for validated route params
Consider reading and validating the whole route params object through the H3 utility when it preserves behavior.
h3/request/prefer-validated-router-paramssrc/rule-packs/h3/rules/prefer-validated-router-params.ts Upstream docs Run this rule
pnpm vite-doctor . --rules h3/request/prefer-validated-router-params
Why it matters
Raw request input and validation can drift apart when they are separate operations. Nitro and h3 provide validated helpers that keep parsing and validation coupled at the request boundary.
Recommended fix
Consider getValidatedRouterParams only if using a validator callback preserves behavior; otherwise keep the read and validation separate. In H3 v1, false means validation failed, and the helper returns raw input when the callback returns true, null, or undefined.
Useful links
Example
Use the helper with an object-returning parser
Before
import { z } from "zod"
const schema = z.object({ name: z.string() })
export default defineEventHandler(async (event) => {
const input = await getRouterParams(event)
const value = schema.parse(input)
return value
})
After
import { z } from "zod"
const schema = z.object({ name: z.string() })
export default defineEventHandler(async (event) => {
const value = await getValidatedRouterParams(event, (input) => schema.parse(input))
return value
})