@remix-run/router 1.1.0-pre.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -18
- package/dist/router.cjs.js +18 -14
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +18 -14
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +18 -14
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/utils.ts +26 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
-
## 1.1.0
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
This release introduces support for [Optional Route Segments](https://github.com/remix-run/react-router/issues/9546). Now, adding a `?` to the end of any path segment will make that entire segment optional. This works for both static segments and dynamic parameters.
|
|
6
|
+
|
|
7
|
+
**Optional Params Examples**
|
|
8
|
+
|
|
9
|
+
- Path `lang?/about` will match:
|
|
10
|
+
- `/:lang/about`
|
|
11
|
+
- `/about`
|
|
12
|
+
- Path `/multistep/:widget1?/widget2?/widget3?` will match:
|
|
13
|
+
- `/multistep`
|
|
14
|
+
- `/multistep/:widget1`
|
|
15
|
+
- `/multistep/:widget1/:widget2`
|
|
16
|
+
- `/multistep/:widget1/:widget2/:widget3`
|
|
17
|
+
|
|
18
|
+
**Optional Static Segment Example**
|
|
19
|
+
|
|
20
|
+
- Path `/home?` will match:
|
|
21
|
+
- `/`
|
|
22
|
+
- `/home`
|
|
23
|
+
- Path `/fr?/about` will match:
|
|
24
|
+
- `/about`
|
|
25
|
+
- `/fr/about`
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
|
6
28
|
|
|
7
|
-
-
|
|
8
|
-
- You can now denote optional path segments with a `?` as the last character in a path segment
|
|
9
|
-
- Optional params examples
|
|
10
|
-
- `:lang?/about` will get expanded and match:
|
|
11
|
-
- `/:lang/about`
|
|
12
|
-
- `/about`
|
|
13
|
-
- `/multistep/:widget1?/widget2?/widget3?` will get expanded and match:
|
|
14
|
-
- `/multistep/:widget1/:widget2/:widget3`
|
|
15
|
-
- `/multistep/:widget1/:widget2`
|
|
16
|
-
- `/multistep/:widget1`
|
|
17
|
-
- `/multistep`
|
|
18
|
-
- Optional static segment example
|
|
19
|
-
- `/fr?/about` will get expanded and match:
|
|
20
|
-
- `/fr/about`
|
|
21
|
-
- `/about`
|
|
29
|
+
- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
|
|
22
30
|
|
|
23
31
|
### Patch Changes
|
|
24
32
|
|
|
@@ -44,9 +52,10 @@ function Comp() {
|
|
|
44
52
|
}
|
|
45
53
|
```
|
|
46
54
|
|
|
47
|
-
- Fix requests sent to revalidating loaders so they reflect a GET request ([#9660](https://github.com/remix-run/react-router/pull/9660))
|
|
48
55
|
- Persist `headers` on `loader` `request`'s after SSR document `action` request ([#9721](https://github.com/remix-run/react-router/pull/9721))
|
|
49
|
-
-
|
|
56
|
+
- Fix requests sent to revalidating loaders so they reflect a GET request ([#9660](https://github.com/remix-run/react-router/pull/9660))
|
|
57
|
+
- Fix issue with deeply nested optional segments ([#9727](https://github.com/remix-run/react-router/pull/9727))
|
|
58
|
+
- GET forms now expose a submission on the loading navigation ([#9695](https://github.com/remix-run/react-router/pull/9695))
|
|
50
59
|
- Fix error boundary tracking for multiple errors bubbling to the same boundary ([#9702](https://github.com/remix-run/react-router/pull/9702))
|
|
51
60
|
|
|
52
61
|
## 1.0.5
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.1.0
|
|
2
|
+
* @remix-run/router v1.1.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -691,22 +691,26 @@ function explodeOptionalSegments(path) {
|
|
|
691
691
|
if (rest.length === 0) {
|
|
692
692
|
// Intepret empty string as omitting an optional segment
|
|
693
693
|
// `["one", "", "three"]` corresponds to omitting `:two` from `/one/:two?/three` -> `/one/three`
|
|
694
|
-
return isOptional ? [""
|
|
694
|
+
return isOptional ? [required, ""] : [required];
|
|
695
695
|
}
|
|
696
696
|
|
|
697
697
|
let restExploded = explodeOptionalSegments(rest.join("/"));
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
698
|
+
let result = []; // All child paths with the prefix. Do this for all children before the
|
|
699
|
+
// optional version for all children so we get consistent ordering where the
|
|
700
|
+
// parent optional aspect is preferred as required. Otherwise, we can get
|
|
701
|
+
// child sections interspersed where deeper optional segments are higher than
|
|
702
|
+
// parent optional segments, where for example, /:two would explodes _earlier_
|
|
703
|
+
// then /:one. By always including the parent as required _for all children_
|
|
704
|
+
// first, we avoid this issue
|
|
705
|
+
|
|
706
|
+
result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/"))); // Then if this is an optional value, add all child versions without
|
|
707
|
+
|
|
708
|
+
if (isOptional) {
|
|
709
|
+
result.push(...restExploded);
|
|
710
|
+
} // for absolute paths, ensure `/` instead of empty segment
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
return result.map(exploded => path.startsWith("/") && exploded === "" ? "/" : exploded);
|
|
710
714
|
}
|
|
711
715
|
|
|
712
716
|
function rankRouteBranches(branches) {
|