Simplify code examples for dynamic API routes (#22546)

Deep matching destructuring syntax is hard to understand and read vs. `const { ... } = req.query`.
This commit is contained in:
devuxer 2021-02-26 10:43:41 -08:00 committed by GitHub
parent 1ba5c0acc7
commit a289d38057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,10 +17,7 @@ For example, the API route `pages/api/post/[pid].js` has the following code:
```js
export default function handler(req, res) {
const {
query: { pid },
} = req
const { pid } = req.query
res.end(`Post: ${pid}`)
}
```
@ -69,10 +66,7 @@ An API route for `pages/api/post/[...slug].js` could look like this:
```js
export default function handler(req, res) {
const {
query: { slug },
} = req
const { slug } = req.query
res.end(`Post: ${slug.join(', ')}`)
}
```