Nuxt module that helps you add validation to your route, inspired by SvelteKit.
-
Add
nuxt-param-validators
dependency to your project# Using yarn yarn add --dev nuxt-param-validators # Using pnpm pnpm add -D nuxt-param-validators # Using npm npm install --save-dev nuxt-param-validators
-
Add
nuxt-param-validators
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({ modules: [ 'nuxt-param-validators' ] })
-
Create a validator in the
validators
dir// validators/is-number.ts export default defineParamValidator(param => /^\d+$/.test(param))
-
Rename your route, eg:
pages/[id=is-number].vue