Skip to content

Commit ce1eb3e

Browse files
committed
docs: note about slow routes
1 parent f4289d3 commit ce1eb3e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/docs/guide/essentials/route-matching-syntax.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,25 @@ You can play around with the matching syntax [in the playground](https://paths.e
124124
## Debugging
125125

126126
If you need to dig how your routes are transformed into a regex to understand why a route isn't being matched or, to report a bug, you can use the [path ranker tool](https://paths.esm.dev/?p=AAMeJSyAwR4UbFDAFxAcAGAIJXMAAA..#). It supports sharing your routes through the URL.
127+
128+
## Avoiding slow regex
129+
130+
When using custom regex, make sure to avoid using slow regex patterns. For example, using `.*` will match any character and can lead to **serious performance issues** if it's combined with a repeatable modifier `*` or `+` and anything after it:
131+
132+
```ts
133+
const routes = [
134+
// This creates a very slow regex because of the greedy `.*` followed by `*` and a static string
135+
{ path: '/:pathMatch(.*)*/something-at-the-end' },
136+
]
137+
```
138+
139+
In practice, use these _match everything_ params only **in the very end of the URL**. If you need them in the middle of the path, **do not make them repeatable**:
140+
141+
```ts
142+
const routes = [
143+
// This is fine because the `.*` is at the end
144+
{ path: '/:pathMatch(.*)/something-at-the-end' },
145+
]
146+
```
147+
148+
This matches the same routes but without an array of params and it's much faster.

0 commit comments

Comments
 (0)