Skip to content

Commit 1fed29d

Browse files
committed
route pattern parts section
1 parent c85cb24 commit 1fed29d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

packages/route-pattern/README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ for (const match of matcher.matches(url)) {
5050
// products/:id -> { id: 'sku-electronics-12345' }
5151
```
5252

53-
## Writing patterns
53+
## Route pattern parts
5454

5555
Route patterns may specify any combination of protocol, hostname, pathname, and search:
5656

@@ -64,6 +64,13 @@ Route patterns may specify any combination of protocol, hostname, pathname, and
6464

6565
**Note:** In route patterns, hostnames must begin with `://` to distinguish them from pathnames
6666

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+
6774
### Wildcards
6875

6976
| | protocol | hostname | pathname | search |
@@ -85,39 +92,39 @@ As a result, wildcards correspond to these regular expressions:
8592
| pathname | `/[^/]*/` | `/.*/` |
8693

8794
```ts
88-
'/files/*'
95+
'/files/*';
8996
// ✓ matches: /files/photo.jpg
9097
// ✗ doesn't match: /files/2023/photo.jpg
9198

92-
'/docs/**'
99+
'/docs/**';
93100
// ✓ matches: /docs/api/v1/intro.html
94101
// ✗ doesn't match: /docs (no trailing content)
95102

96-
'://*.example.com'
103+
'://*.example.com';
97104
// ✓ matches: ://cdn.example.com
98105
// ✗ doesn't match: ://api.staging.example.com
99106

100-
'://**.api.com'
107+
'://**.api.com';
101108
// ✓ matches: ://tenant.v1.api.com
102109
// ✗ doesn't match: ://api.com (no prefix)
103110
```
104111

105112
Route patterns can have multiple wildcards, even within the same segment.
106113

107114
```ts
108-
'/assets/**/static/**/*.css'
115+
'/assets/**/static/**/*.css';
109116
// ✓ matches: /assets/v2/themes/static/dark/main.css
110117
// ✗ doesn't match: /assets/v2/themes/static/main.js
111118

112-
'://us-**.cdn.com/cars/*-*'
119+
'://us-**.cdn.com/cars/*-*';
113120
// ✓ matches: ://us-east.staging.cdn.com/cars/audi-a4.jpg
114121
// ✗ doesn't match: ://us-east.staging.cdn.com/cars/toyota.jpg
115122
```
116123

117124
Wildcards only match characters within the same part of the URL:
118125

119126
```ts
120-
'://api.**/users'
127+
'://api.**/users';
121128
// ✓ matches: ://api.example.com/users
122129
// ✗ doesn't match: ://api.example.com/123/users
123130
```
@@ -131,6 +138,7 @@ Wildcards only match characters within the same part of the URL:
131138
Params, like wildcards, match dynamic parts of the URL but they also give you access to the matched values.
132139

133140
A param is written as:
141+
134142
- `:` followed by a name for capturing anything within a segment (similar to `*`)
135143
- `::` followed by a name for capturing anything, even across multiple segments (similar to `**`)
136144

@@ -198,7 +206,7 @@ Params can be mixed with static text, wildcards, and even other params:
198206
Params only match characters within the same part of the URL:
199207

200208
```ts
201-
'://api.::domain/users'
209+
'://api.::domain/users';
202210
// ✓ matches: ://api.example.com/users → { domain: 'example.com' }
203211
// ✗ doesn't match: ://api.example.com/123/users
204212
```
@@ -326,4 +334,4 @@ Use backslash `\` to escape special characters in the patterns language: `:`, `*
326334

327335
### JavaScript identifier
328336

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

Comments
 (0)