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:
parent
1ba5c0acc7
commit
a289d38057
1 changed files with 2 additions and 8 deletions
|
@ -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(', ')}`)
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue