Skip to content

Commit 51840e1

Browse files
docs: note about express named wildcard parameters
1 parent 8be48f0 commit 51840e1

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

content/controllers.md

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ findAll() {
202202

203203
The `'abcd/*'` route path will match `abcd/`, `abcd/123`, `abcd/abc`, and so on. The hyphen ( `-`) and the dot (`.`) are interpreted literally by string-based paths.
204204

205+
This approach works on both Express and Fastify. However, with the latest release of Express (v5), the routing system has become more strict. In pure Express, you must use a named wildcard to make the route work—for example, `abcd/*splat`, where `splat` is simply the name of the wildcard parameter and has no special meaning. You can name it anything you like. That said, since Nest provides a compatibility layer for Express, you can still use the asterisk (`*`) as a wildcard.
206+
205207
When it comes to asterisks used in the **middle of a route**, Express requires named wildcards (e.g., `ab{{ '{' }}*splat}cd`), while Fastify does not support them at all.
206208

207209
#### Status code

content/middlewares.md

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ forRoutes({
137137
});
138138
```
139139

140+
> info **Hint** `splat` is simply the name of the wildcard parameter and has no special meaning. You can name it anything you like, for example, `*wildcard`.
141+
140142
The `'abcd/*'` route path will match `abcd/1`, `abcd/123`, `abcd/abc`, and so on. The hyphen ( `-`) and the dot (`.`) are interpreted literally by string-based paths. However, `abcd/` with no additional characters will not match the route. For this, you need to wrap the wildcard in braces to make it optional:
141143

142144
```typescript

content/migration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ After years of development, Express v5 was officially released in 2024 and becam
1212

1313
One of the most notable updates in Express v5 is the revised path route matching algorithm. The following changes have been introduced to how path strings are matched with incoming requests:
1414

15-
- The wildcard `*` must have a name, matching the behavior of parameters :, use `/*splat` or `/{{ '{' }}*splat}` instead of `/*`
15+
- The wildcard `*` must have a name, matching the behavior of parameters: use `/*splat` or `/{{ '{' }}*splat}` instead of `/*`. `splat` is simply the name of the wildcard parameter and has no special meaning. You can name it anything you like, for example, `*wildcard`
1616
- The optional character `?` is no longer supported, use braces instead: `/:file{{ '{' }}.:ext}`.
1717
- Regexp characters are not supported.
1818
- Some characters have been reserved to avoid confusion during upgrade `(()[]?+!)`, use `\` to escape them.
@@ -38,7 +38,7 @@ findAll() {
3838
}
3939
```
4040

41-
> warning **Warning** Note that `*splat` is a named wildcard that matches any path without the root path. If you need to match the root path as well (`/users`), you can use `/users/{{ '{' }}*splat}`, wrapping the wildcard in braces (optional group).
41+
> warning **Warning** Note that `*splat` is a named wildcard that matches any path without the root path. If you need to match the root path as well (`/users`), you can use `/users/{{ '{' }}*splat}`, wrapping the wildcard in braces (optional group). Note that `splat` is simply the name of the wildcard parameter and has no special meaning. You can name it anything you like, for example, `*wildcard`.
4242
4343
Similarly, if you have a middleware that runs on all routes, you may need to update the path to use a named wildcard:
4444

0 commit comments

Comments
 (0)