Skip to content

Commit

Permalink
Clarify inheritance behaviour of route params in .params (expressjs#1515
Browse files Browse the repository at this point in the history
)

Current documentation specifies router param callbacks are not inherited
by mounted apps or routers, but does not also specify they do not
inherit from parent routers either.
  • Loading branch information
MaoShizhong committed May 17, 2024
1 parent f9b3563 commit 7e2d60b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _includes/api/en/4x/app-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ app.param('user', function (req, res, next, id) {
})
```

Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers. Hence, param callbacks defined on `app` will be triggered only by route parameters defined on `app` routes.
Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers, nor are they triggered for route parameters inherited from parent routers. Hence, param callbacks defined on `app` will be triggered only by route parameters defined on `app` routes.

All param callbacks will be called before any handler of any route in which the param occurs, and they will each be called only once in a request-response cycle, even if the parameter is matched in multiple routes, as shown in the following examples.

Expand Down
2 changes: 1 addition & 1 deletion _includes/api/en/4x/router-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ router.param('user', function (req, res, next, id) {
})
```

Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers. Hence, param callbacks defined on `router` will be triggered only by route parameters defined on `router` routes.
Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers, nor are they triggered for route parameters inherited from parent routers. Hence, param callbacks defined on `router` will be triggered only by route parameters defined on `router` routes.

A param callback will be called only once in a request-response cycle, even if the parameter is matched in multiple routes, as shown in the following examples.

Expand Down
2 changes: 1 addition & 1 deletion _includes/api/en/5x/app-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ app.param('user', (req, res, next, id) => {
})
```

Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers. Hence, param callbacks defined on `app` will be triggered only by route parameters defined on `app` routes.
Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers, nor are they triggered for route parameters inherited from parent routers. Hence, param callbacks defined on `app` will be triggered only by route parameters defined on `app` routes.

All param callbacks will be called before any handler of any route in which the param occurs, and they will each be called only once in a request-response cycle, even if the parameter is matched in multiple routes, as shown in the following examples.

Expand Down
2 changes: 1 addition & 1 deletion _includes/api/en/5x/router-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ router.param('user', (req, res, next, id) => {
})
```

Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers. Hence, param callbacks defined on `router` will be triggered only by route parameters defined on `router` routes.
Param callback functions are local to the router on which they are defined. They are not inherited by mounted apps or routers, nor are they triggered for route parameters inherited from parent routers. Hence, param callbacks defined on `router` will be triggered only by route parameters defined on `router` routes.

A param callback will be called only once in a request-response cycle, even if the parameter is matched in multiple routes, as shown in the following examples.

Expand Down

0 comments on commit 7e2d60b

Please sign in to comment.