www/apps/resources/app/lint/rules/route-params-must-be-defined/page.mdx
export const metadata = {
title: route-params-must-be-defined - ESLint plugin rules,
}
This rule requires properties accessed on req.params in an API route handler to correspond to a [param] folder in the route path.
error. This rule is enabled in the recommended preset.
This rule targets route.ts and route.js files in your project's src/api directory. It reports access to a req.params property that has no matching [param] folder in the route path.
The following code is reported by the rule, since the route has no foo parameter:
export const GET = (req, res) => {
const x = req.params.foo
}
Instead, access a parameter defined by a [param] folder:
export const GET = (req, res) => {
const x = req.params.id
}
A route parameter is only available on req.params when a [param] folder defines it in the route path. Accessing an undefined parameter returns undefined, which often points to a typo or a missing folder.
Learn more in the Route Parameters documentation.
This rule isn't auto-fixable.