Skip to content

Improve clarity of next('route') usage in Route Handlers section #2034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from

Conversation

yelishgiri
Copy link

@yelishgiri yelishgiri commented Aug 8, 2025

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:

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

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.

@yelishgiri yelishgiri requested a review from a team as a code owner August 8, 2025 06:51
Copy link

netlify bot commented Aug 8, 2025

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit f16c42e
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/689fb9b3696a350008686ee8
😎 Deploy Preview https://deploy-preview-2034--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

github-actions bot commented Aug 8, 2025

🚦 Lighthouse Results (Mobile & Desktop)

URL Device Perf A11y Best Practices
/ mobile 🔴 73 🟢 100 🟢 96
/en/blog/posts.html mobile 🔴 73 🟢 96 🟢 96
/en/5x/api.html mobile 🔴 66 🟢 95 🟢 96
/ desktop 🟢 93 🟢 100 🟢 96
/en/blog/posts.html desktop 🟢 96 🟢 96 🟢 93
/en/5x/api.html desktop 🟢 98 🟢 95 🟢 96

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants