docs: Improve clarity of next('route') usage in Route Handlers section#2034
Merged
bjohansebas merged 3 commits intoexpressjs:gh-pagesfrom Dec 14, 2025
Merged
Conversation
✅ Deploy Preview for expressjscom-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
🚦 Lighthouse Results (Mobile & Desktop)
|
bjohansebas
reviewed
Aug 15, 2025
Comment on lines
+246
to
+248
| 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: |
Member
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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.
Removed a duplicate explanation of next('route') to avoid redundancy.
The section now introduces the concept once and flows directly into the example,
making the docs more concise and easier to read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR adds a concrete example demonstrating the use of next('route') in the “Route handlers” section of the Express routing documentation.
Currently, the docs mention next('route') but don’t show a simple, self-contained example, which could make it unclear for new users. This change:
Adds a GET /user/:id example that uses next('route') to skip to the next matching route.
Includes a short bullet-point explanation of the behavior for two different request paths (/user/5 and /user/0).
Before:
The section explains next('route') but doesn’t show a minimal code sample demonstrating it in action.
After:
The section now contains:
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
Why this change improves the docs:
Makes the next('route') behavior obvious without requiring guesswork.
Matches the style and tone of existing Express documentation.
Adds a practical example to complement the textual explanation.