Skip to content

Commit ef068f8

Browse files
HarshithaKPdougwilson
authored andcommitted
Add router@2.0.0-beta.1 changes to express 5 migration guide
closes #1114
1 parent 2fc9055 commit ef068f8

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

_includes/api/en/5x/app-use.md

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,7 @@ app.use('/abcd', function (req, res, next) {
9797
This will match paths starting with `/abcd` and `/abd`:
9898

9999
```js
100-
app.use('/abc?d', function (req, res, next) {
101-
next()
102-
})
103-
```
104-
105-
This will match paths starting with `/abcd`, `/abbcd`, `/abbbbbcd`, and so on:
106-
107-
```js
108-
app.use('/ab+cd', function (req, res, next) {
109-
next()
110-
})
111-
```
112-
113-
This will match paths starting with `/abcd`, `/abxcd`, `/abFOOcd`, `/abbArcd`, and so on:
114-
115-
```js
116-
app.use('/ab*cd', function (req, res, next) {
117-
next()
118-
})
119-
```
120-
121-
This will match paths starting with `/ad` and `/abcd`:
122-
123-
```js
124-
app.use('/a(bc)?d', function (req, res, next) {
100+
app.use('/ab(c?)d', function (req, res, next) {
125101
next()
126102
})
127103
```

en/guide/migrating-5.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ See the [pull request](https://github.com/expressjs/express/pull/2237) for a lis
4444
**Changed**
4545

4646
<ul class="doclist">
47+
<li><a href="#path-syntax">Path route matching syntax</a></li>
4748
<li><a href="#app.router">app.router</a></li>
4849
<li><a href="#req.host">req.host</a></li>
4950
<li><a href="#req.query">req.query</a></li>
@@ -112,6 +113,20 @@ The `res.sendfile()` function has been replaced by a camel-cased version `res.se
112113

113114
<h3>Changed</h3>
114115

116+
<h4 id="path-syntax">Path route matching syntax</h4>
117+
118+
Path route matching syntax is when a string is supplied as the first parameter to the `app.all()`, `app.use()`, `app.METHOD()`, `router.all()`, `router.METHOD()`, and `router.use()` APIs. The following changes have been made to how the path string is matched to an incoming request:
119+
120+
- Add new `?`, `*`, and `+` parameter modifiers.
121+
- Matching group expressions are only RegExp syntax.
122+
* `(*)` is no longer valid and must be written as `(.*)`, for example.
123+
- Named matching groups no longer available by position in `req.params`.
124+
* `/:foo(.*)` only captures as `req.params.foo` and not available as `req.params[0]`.
125+
- Regular expressions can only be used in a matching group.
126+
* `/\\d+` is no longer valid and must be written as `/(\\d+)`.
127+
- Special `*` path segment behavior removed.
128+
* `/foo/*/bar` will match a literal `*` as the middle segment.
129+
115130
<h4 id="app.router">app.router</h4>
116131

117132
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.

0 commit comments

Comments
 (0)