You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BREAKING CHANGE: Upgraded path-to-regexp from 3.x to 8.x
7
+
8
+
This upgrade was necessary to resolve security vulnerabilities. The new version introduces two breaking changes that require updates to your application:
9
+
10
+
1. Optional Path Parameter Syntax Change
11
+
- Old syntax: `/resources/:id?`
12
+
- New syntax: `/resources{/id}`
13
+
14
+
This change is required because in path-to-regexp 8.x, the `?` character is reserved for query parameters and will throw a parsing error when used at the end of a path.
15
+
16
+
2. Root Path Matching Behavior Change
17
+
- In v3.x, root path `/` would match any path starting with `/`
18
+
- In v8.x, root path `/` only matches exactly `/`
19
+
- To match both root and child paths, use the wildcard pattern `/{*path}`
20
+
21
+
Example migration:
22
+
```javascript
23
+
// Before
24
+
constroutes= {
25
+
'/': rootSaga,
26
+
'/resources/:id?': resourceSaga
27
+
};
28
+
29
+
// After
30
+
constroutes= {
31
+
'/{*path}': rootSaga, // if you want to match all routes
32
+
'/resources{/id}': resourceSaga
33
+
};
34
+
```
35
+
For more details about path matching and troubleshooting, see [path-to-regexp documentation](https://github.com/pillarjs/path-to-regexp#errors).
Given the webapp url is `localhost/datasets/50/edit`
214
220
215
221
and that we have the following configuration
216
222
217
223
```javascript
218
-
function*editDatasetSaga ({datasetId}){
219
-
// do something
224
+
function*editDatasetSaga({ datasetId }) {
225
+
// do something
220
226
}
221
227
222
228
constroutes= {
223
-
"/datasets/add": datasetsSaga,
224
-
"/datasets/:datasetId/edit": editDatasetSaga
229
+
'/datasets/add': datasetsSaga,
230
+
'/datasets/:datasetId/edit': editDatasetSaga,
225
231
};
226
232
```
227
233
@@ -234,24 +240,65 @@ the `editDatasetsSaga` is cancelled, and when its done, restarted with the new v
234
240
Only sagas matching on a route which parameter change are restarted.
235
241
236
242
### Route matching with optionnal parameters
243
+
237
244
Given the webapp url is `localhost/datasets/add/550`
238
245
239
246
and that we have the following configuration
240
247
241
248
```javascript
242
-
function*editDatasetSaga ({datasetId}){
243
-
// do something
249
+
function*editDatasetSaga({ datasetId }) {
250
+
// do something
244
251
}
245
252
246
253
constroutes= {
247
-
"/datasets/add/:connectionId?": datasetsSaga,
248
-
"/datasets/:datasetId/edit": editDatasetSaga
254
+
'/datasets/add{/:connectionId}': datasetsSaga,
255
+
'/datasets/:datasetId/edit': editDatasetSaga,
249
256
};
250
257
```
258
+
251
259
datasetSaga will be executed
252
260
253
261
if the route change to `localhost/datasets/add`
254
262
255
-
the `datasetsSaga` will be restarted since it still match on `/datasets/add/:connectionId?` route and that the parameter has changed from being a value to being absent.
263
+
the `datasetsSaga` will be restarted since it still match on `/datasets/add{/:connectionId}` route and that the parameter has changed from being a value to being absent.
264
+
265
+
the {/:connectionId} at the end of path means /connectionId is optional.
266
+
267
+
### Root Path Matching
268
+
269
+
The root path `/` has special matching behavior that's important to understand:
270
+
271
+
1. Exact root path matching:
272
+
273
+
```javascript
274
+
constroutes= {
275
+
'/':function*rootSaga() {
276
+
yieldtake('SOMETHING');
277
+
},
278
+
};
279
+
```
280
+
281
+
- Only matches exactly `/`
282
+
- Does not match child routes like `/tasks` or `/users/123`
283
+
- This is because path-to-regexp treats the root path `/` differently than other routes - it won't do partial matching even when `exact` is false
284
+
- If you want `/` to match any path that starts with `/`, you need to use a wildcard pattern like `/{*path}`
285
+
286
+
2. Matching root and all child routes:
287
+
288
+
```javascript
289
+
constroutes= {
290
+
'/{*path}':function*rootSaga({ path }) {
291
+
yieldtake('SOMETHING');
292
+
},
293
+
};
294
+
```
295
+
296
+
- Matches both root path `/` and all child routes
297
+
- For root path `/`, params will be empty `{}`
298
+
- For child routes, `params.path` will contain the remaining path:
299
+
-`/tasks` → `{ path: 'tasks' }`
300
+
-`/tasks/123` → `{ path: 'tasks/123' }`
301
+
302
+
This pattern is particularly useful when you need a saga to run for all routes in your application while still being able to access the current route path.
256
303
257
-
the ? at the end of the parameter define that it is optional.
304
+
For more details about path matching and troubleshooting, see [path-to-regexp documentation](https://github.com/pillarjs/path-to-regexp#errors).
0 commit comments