Skip to content
Open
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions en/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ 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.

You can use `next('route')` to skip the rest of a route's callbacks and pass control to the next route. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two sentences repeat content, whereas if the message can be improved and shown through the example, we shouldn’t repeat the content that was already mentioned earlier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I’ve removed the second sentence so the explanation is given only once, with the example showing the behavior directly. This should make the section more concise and avoid redundancy.


```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