@@ -50,7 +50,7 @@ for (const match of matcher.matches(url)) {
50
50
// products/:id -> { id: 'sku-electronics-12345' }
51
51
```
52
52
53
- ## Writing patterns
53
+ ## Route pattern parts
54
54
55
55
Route patterns may specify any combination of protocol, hostname, pathname, and search:
56
56
@@ -64,6 +64,13 @@ Route patterns may specify any combination of protocol, hostname, pathname, and
64
64
65
65
** Note:** In route patterns, hostnames must begin with ` :// ` to distinguish them from pathnames
66
66
67
+ | | protocol | hostname | pathname | search |
68
+ | --------------------------- | ---------------- | ---------------- | ----------------------------- | -------------- |
69
+ | Case-sensitivity | Case-insensitive | Case-insensitive | Case-sensitive | Case-sensitive |
70
+ | Match behavior when omitted | Any protocol | Any hostname | Empty pathname: ` "" ` or ` "/" ` | Any search |
71
+
72
+ ## Pattern modifiers
73
+
67
74
### Wildcards
68
75
69
76
| | protocol | hostname | pathname | search |
@@ -85,39 +92,39 @@ As a result, wildcards correspond to these regular expressions:
85
92
| pathname | ` /[^/]*/ ` | ` /.*/ ` |
86
93
87
94
``` ts
88
- ' /files/*'
95
+ ' /files/*' ;
89
96
// ✓ matches: /files/photo.jpg
90
97
// ✗ doesn't match: /files/2023/photo.jpg
91
98
92
- ' /docs/**'
99
+ ' /docs/**' ;
93
100
// ✓ matches: /docs/api/v1/intro.html
94
101
// ✗ doesn't match: /docs (no trailing content)
95
102
96
- ' ://*.example.com'
103
+ ' ://*.example.com' ;
97
104
// ✓ matches: ://cdn.example.com
98
105
// ✗ doesn't match: ://api.staging.example.com
99
106
100
- ' ://**.api.com'
107
+ ' ://**.api.com' ;
101
108
// ✓ matches: ://tenant.v1.api.com
102
109
// ✗ doesn't match: ://api.com (no prefix)
103
110
```
104
111
105
112
Route patterns can have multiple wildcards, even within the same segment.
106
113
107
114
``` ts
108
- ' /assets/**/static/**/*.css'
115
+ ' /assets/**/static/**/*.css' ;
109
116
// ✓ matches: /assets/v2/themes/static/dark/main.css
110
117
// ✗ doesn't match: /assets/v2/themes/static/main.js
111
118
112
- ' ://us-**.cdn.com/cars/*-*'
119
+ ' ://us-**.cdn.com/cars/*-*' ;
113
120
// ✓ matches: ://us-east.staging.cdn.com/cars/audi-a4.jpg
114
121
// ✗ doesn't match: ://us-east.staging.cdn.com/cars/toyota.jpg
115
122
```
116
123
117
124
Wildcards only match characters within the same part of the URL:
118
125
119
126
``` ts
120
- ' ://api.**/users'
127
+ ' ://api.**/users' ;
121
128
// ✓ matches: ://api.example.com/users
122
129
// ✗ doesn't match: ://api.example.com/123/users
123
130
```
@@ -131,6 +138,7 @@ Wildcards only match characters within the same part of the URL:
131
138
Params, like wildcards, match dynamic parts of the URL but they also give you access to the matched values.
132
139
133
140
A param is written as:
141
+
134
142
- ` : ` followed by a name for capturing anything within a segment (similar to ` * ` )
135
143
- ` :: ` followed by a name for capturing anything, even across multiple segments (similar to ` ** ` )
136
144
@@ -198,7 +206,7 @@ Params can be mixed with static text, wildcards, and even other params:
198
206
Params only match characters within the same part of the URL:
199
207
200
208
``` ts
201
- ' ://api.::domain/users'
209
+ ' ://api.::domain/users' ;
202
210
// ✓ matches: ://api.example.com/users → { domain: 'example.com' }
203
211
// ✗ doesn't match: ://api.example.com/123/users
204
212
```
@@ -326,4 +334,4 @@ Use backslash `\` to escape special characters in the patterns language: `:`, `*
326
334
327
335
### JavaScript identifier
328
336
329
- For the purposes of this spec, JavaScript identifiers match this regular expression: [ /[ a-zA-Z * $0-9] [ a-zA-Z* $0-9 ] \* / ] ( https://regexr.com/8fcn3 )
337
+ For the purposes of this spec, JavaScript identifiers match this regular expression: [ ` /[a-zA-Z_ $0-9][a-zA-Z_ $0-9]*/ ` ] ( https://regexr.com/8fcn3 )
0 commit comments