Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions en/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,24 @@ In Express 4.x, <a href="https://github.com/expressjs/express/issues/2495">the `

You can provide multiple callback functions that behave like [middleware](/{{ page.lang }}/guide/using-middleware.html) to handle a request. The only exception is that these callbacks might invoke `next('route')` to bypass the remaining route callbacks. You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there's no reason to proceed with the current route.

```js
app.get('/user/:id', (req, res, next) => {
if (req.params.id === '0') {
return next('route')
}
res.send(`User ${req.params.id}`)
})

app.get('/user/:id', (req, res) => {
res.send('Special handler for user ID 0')
})
```

In this example:

- `GET /user/5` → handled by first route → sends "User 5"
- `GET /user/0` → first route calls `next('route')`, skipping to the next matching `/user/:id` route

Route handlers can be in the form of a function, an array of functions, or combinations of both, as shown in the following examples.

A single callback function can handle a route. For example:
Expand Down