Skip to content

Commit 8d1731f

Browse files
committed
docs: Document req.params changes in 5.x
Fixes #2090
1 parent 738f860 commit 8d1731f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

en/guide/migrating-5.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ You can find the list of available codemods [here](https://github.com/expressjs/
7171
<li><a href="#app.router">app.router</a></li>
7272
<li><a href="#req.body">req.body</a></li>
7373
<li><a href="#req.host">req.host</a></li>
74+
<li><a href="#req.params">req.params</a></li>
7475
<li><a href="#req.query">req.query</a></li>
7576
<li><a href="#res.clearCookie">res.clearCookie</a></li>
7677
<li><a href="#res.status">res.status</a></li>
@@ -506,14 +507,30 @@ const server = app.listen(8080, '0.0.0.0', (error) => {
506507

507508
The `app.router` object, which was removed in Express 4, has made a comeback in Express 5. In the new version, this object is a just a reference to the base Express router, unlike in Express 3, where an app had to explicitly load it.
508509

509-
<h3 id="req.body">req.body</h3>
510+
<h3 id="req.body">req.body</h3>
510511

511512
The `req.body` property returns `undefined` when the body has not been parsed. In Express 4, it returns `{}` by default.
512513

513514
<h3 id="req.host">req.host</h3>
514515

515516
In Express 4, the `req.host` function incorrectly stripped off the port number if it was present. In Express 5, the port number is maintained.
516517

518+
<h3 id="req.params">req.params</h3>
519+
520+
Parameters specified as wildcards are represented as arrays of segments:
521+
522+
```js
523+
app.get('/*splat', (req, res) => {
524+
// GET /foo/bar
525+
console.dir(req.params)
526+
// => [Object: null prototype] { name: [ 'foo', 'bar' ] }
527+
})
528+
```
529+
530+
Optional parameters that are not matched do not have a key in `req.params`. In 4.x an unmatched wildcard would be an empty string and a `:` parameter made optional by `?` had a key with value `undefined`.
531+
532+
The object has null prototype.
533+
517534
<h3 id="req.query">req.query</h3>
518535

519536
The `req.query` property is no longer a writable property and is instead a getter. The default query parser has been changed from "extended" to "simple".

0 commit comments

Comments
 (0)