Skip to content

Commit 50de3ed

Browse files
committed
docs(api-5): document wildcard parameters in req.params
1 parent 40197d6 commit 50de3ed

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

_includes/api/en/5x/req-params.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
<h3 id='req.params'>req.params</h3>
22

3-
This property is an object containing properties mapped to the [named route "parameters"](/{{ page.lang }}/guide/routing.html#route-parameters). For example, if you have the route `/user/:name`, then the "name" property is available as `req.params.name`. This object defaults to `{}`.
3+
This property is an object containing properties mapped to the [named route "parameters"](/{{ page.lang }}/guide/routing.html#route-parameters). For example, if you have the route `/user/:name`, then the "name" property is available as `req.params.name`. This object defaults to `Object.create(null)`.
44

55
```js
66
// GET /user/tj
77
console.dir(req.params.name)
88
// => "tj"
99
```
1010

11+
Properties corresponding to wildcard parameters are arrays containing separate path segments split on `/`:
12+
13+
```js
14+
app.get('/files/*file', (req, res) => {
15+
console.dir(req.params.file)
16+
// GET /files/note.txt
17+
// => [ 'note.txt' ]
18+
// GET /files/images/image.png
19+
// => [ 'images', 'image.png' ]
20+
})
21+
```
22+
1123
When you use a regular expression for the route definition, capture groups are provided in the array using `req.params[n]`, where `n` is the n<sup>th</sup> capture group.
1224

1325
```js

0 commit comments

Comments
 (0)