docs: improve discoverability of wildcard parameters#2451
Conversation
✅ Deploy Preview for expressjscom-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| }); | ||
| ``` | ||
|
|
||
| Wildcard parameters (`*`) are also supported in Express 5. Unlike named parameters (`:`), they capture one or more path segments and expose them as an array in `req.params`. See the [Wildcards](#wildcards) section above for details and examples. |
There was a problem hiding this comment.
| Wildcard parameters (`*`) are also supported in Express 5. Unlike named parameters (`:`), they capture one or more path segments and expose them as an array in `req.params`. See the [Wildcards](#wildcards) section above for details and examples. | |
| <Alert type="info"> | |
| Wildcard parameters (`*`) are only supports in Express 5. Unlike named parameters (`:`), they capture one or more path segments and expose them as an array in `req.params`. See the [Wildcards](#wildcards) section above or [migration guide](https://expressjs.com/en/guide/migrating-5/#path-route-matching-syntax) for details and examples. | |
| <Alert> |
Add abouve note on page: https://expressjs.com/en/5x/api/request/#reqparams
Some extra, but not necessary. Add alert not on 4x doc https://expressjs.com/en/4x/api/request/#reqparams
<Alert type="alert">
Wildcard parameters (`*`) are introduced in Express 5. Unlike named parameters (`:`), they capture one or more path segments and expose them as an array in `req.params`. See the [migration guide to 5x](https://expressjs.com/en/guide/migrating-5/#path-route-matching-syntax) for details.
<Alert>
There was a problem hiding this comment.
Thanks for the review!
I've addressed the requested changes by:
- Wrapping the wildcard parameter note in an
Alertcomponent. - Adding the wildcard parameter note to the Express 5
req.paramsdocumentation with a link to the migration guide. - Adding the suggested notice to the Express 4
req.paramsdocumentation.
Please let me know if there are any further changes or improvements you'd like me to make. Thanks!
There was a problem hiding this comment.
I'm not sure if this wording is clear. In 4.x there are wildcard parameters, but with no explicit names. These can still be accessed from req.params (so I'd argue that they are parameters) under integer keys (in most cases there's just one unnamed parameter so - req.params[0]). In 4.x wildcards return strings instead of string[] like in 5.x.
There was a problem hiding this comment.
Thanks for pointing that out! That's a good clarification. I'll update the wording to distinguish the Express 4 behavior (req.params[0] returning a string) from the named wildcard parameters introduced in Express 5.
There was a problem hiding this comment.
Yes, I think this is best fit.
<Alert type="info">
In Express 4, wildcards (`*`) are unnamed, whereas in Express 5, wildcards must be explicitly named (e.g., `/*splat`). Please check the [migration guide to 5.x](https://expressjs.com/en/guide/migrating-5/#path-route-matching-syntax) before upgrading your routes.
</Alert>
There was a problem hiding this comment.
Thanks! I've updated the wording accordingly.
There was a problem hiding this comment.
Kindly tell if anything else is required. Thanks
|
|
||
| <Alert type="info"> | ||
|
|
||
| Wildcard parameters (`*`) are only supported in Express 5. Unlike named parameters (`:`), they capture one or more path segments and expose them as an array in `req.params`. See the [Wildcards](#wildcards) section above or the [migration guide](https://expressjs.com/en/guide/migrating-5/#path-route-matching-syntax) for details and examples. |
There was a problem hiding this comment.
I don't think we need to say "Express 5" anymore. The guides are versioned, so that redundancy isn't necessary
There was a problem hiding this comment.
Thanks for the feedback! I've simplified the wording by removing the redundant "Express 5" reference from the versioned guides while keeping the migration guide reference.
bjohansebas
left a comment
There was a problem hiding this comment.
Hmm, I need to take a closer look at this. I feel like we're breaking the reading flow, so I'll briefly block it for now
Co-authored-by: shubham oulkar <oulkarshubhu@gmail.com> Signed-off-by: Akshay Anand <147163632+Akshay4754@users.noreply.github.com>
37336e9 to
fa31c8a
Compare

Summary
This PR improves the discoverability of wildcard parameters in the Express 5 Route parameters documentation.
Instead of duplicating the existing wildcard documentation, it adds a short note that points readers to the existing Wildcards section.
Fixes #1891