how to use param matcher in Sveltekit
12/22/2022, 8:44:27 PM
by Leo Voon
For example, let’s say we have a dynamic route ends with post/[id]
we want the id to be integer only,
- Rename the route directory from
[id]to[id=integer] - Go to
srcfolder, create a directory calledparams, and create a file namedintegerin it. - And here is where you implement your matcher.
// src/params/integer.ts
import type { ParamMatcher } from '@sveltejs/kit'
export const match: ParamMatcher = (param) => {
return /^[0-9]+$/.test(param)
}