Unverified Commit a289d380 authored by devuxer's avatar devuxer Committed by GitHub

Simplify code examples for dynamic API routes (#22546)

Deep matching destructuring syntax is hard to understand and read vs. `const { ... } = req.query`.
parent 1ba5c0ac
......@@ -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(', ')}`)
}
```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment