@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/dist/router.js CHANGED
@@ -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
  *
@@ -653,22 +653,26 @@ function explodeOptionalSegments(path) {
653
653
  if (rest.length === 0) {
654
654
  // Intepret empty string as omitting an optional segment
655
655
  // `["one", "", "three"]` corresponds to omitting `:two` from `/one/:two?/three` -> `/one/three`
656
- return isOptional ? ["", required] : [required];
656
+ return isOptional ? [required, ""] : [required];
657
657
  }
658
658
 
659
659
  let restExploded = explodeOptionalSegments(rest.join("/"));
660
- return restExploded.flatMap(subpath => {
661
- // /one + / + :two/three -> /one/:two/three
662
- let requiredExploded = subpath === "" ? required : required + "/" + subpath; // For optional segments, return the exploded path _without_ current segment first (`subpath`)
663
- // and exploded path _with_ current segment later (`subpath`)
664
- // This ensures that exploded paths are emitted in priority order
665
- // `/one/three/:four` will come before `/one/three/:five`
666
-
667
- return isOptional ? [subpath, requiredExploded] : [requiredExploded];
668
- }).map(exploded => {
669
- // for absolute paths, ensure `/` instead of empty segment
670
- return path.startsWith("/") && exploded === "" ? "/" : exploded;
671
- });
660
+ let result = []; // All child paths with the prefix. Do this for all children before the
661
+ // optional version for all children so we get consistent ordering where the
662
+ // parent optional aspect is preferred as required. Otherwise, we can get
663
+ // child sections interspersed where deeper optional segments are higher than
664
+ // parent optional segments, where for example, /:two would explodes _earlier_
665
+ // then /:one. By always including the parent as required _for all children_
666
+ // first, we avoid this issue
667
+
668
+ result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/"))); // Then if this is an optional value, add all child versions without
669
+
670
+ if (isOptional) {
671
+ result.push(...restExploded);
672
+ } // for absolute paths, ensure `/` instead of empty segment
673
+
674
+
675
+ return result.map(exploded => path.startsWith("/") && exploded === "" ? "/" : exploded);
672
676
  }
673
677
 
674
678
  function rankRouteBranches(branches) {