@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 CHANGED
@@ -1,24 +1,32 @@
1
1
  # `@remix-run/router`
2
2
 
3
- ## 1.1.0-pre.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
- - Support for optional path segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
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
- - `GET` forms now expose a submission on the loading navigation ([#9695](https://github.com/remix-run/react-router/pull/9695))
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.1.0-pre.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 ? ["", required] : [required];
694
+ return isOptional ? [required, ""] : [required];
695
695
  }
696
696
 
697
697
  let restExploded = explodeOptionalSegments(rest.join("/"));
698
- return restExploded.flatMap(subpath => {
699
- // /one + / + :two/three -> /one/:two/three
700
- let requiredExploded = subpath === "" ? required : required + "/" + subpath; // For optional segments, return the exploded path _without_ current segment first (`subpath`)
701
- // and exploded path _with_ current segment later (`subpath`)
702
- // This ensures that exploded paths are emitted in priority order
703
- // `/one/three/:four` will come before `/one/three/:five`
704
-
705
- return isOptional ? [subpath, requiredExploded] : [requiredExploded];
706
- }).map(exploded => {
707
- // for absolute paths, ensure `/` instead of empty segment
708
- return path.startsWith("/") && exploded === "" ? "/" : exploded;
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) {