Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba28c5c

Browse files
committed
docs: Document req.params changes in 5.x
Fixes#2090
1 parent738f860 commitba28c5c

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><ahref="#app.router">app.router</a></li>
7272
<li><ahref="#req.body">req.body</a></li>
7373
<li><ahref="#req.host">req.host</a></li>
74+
<li><ahref="#req.params">req.params</a></li>
7475
<li><ahref="#req.query">req.query</a></li>
7576
<li><ahref="#res.clearCookie">res.clearCookie</a></li>
7677
<li><ahref="#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-
<h3id="req.body">req.body</h3>
510+
<h3id="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
<h3id="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+
<h3id="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] { splat: [ '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
<h3id="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)

[8]ページ先頭

©2009-2025 Movatter.jp