@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.
@@ -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
  *
@@ -693,22 +693,26 @@
693
693
  if (rest.length === 0) {
694
694
  // Intepret empty string as omitting an optional segment
695
695
  // `["one", "", "three"]` corresponds to omitting `:two` from `/one/:two?/three` -> `/one/three`
696
- return isOptional ? ["", required] : [required];
696
+ return isOptional ? [required, ""] : [required];
697
697
  }
698
698
 
699
699
  let restExploded = explodeOptionalSegments(rest.join("/"));
700
- return restExploded.flatMap(subpath => {
701
- // /one + / + :two/three -> /one/:two/three
702
- let requiredExploded = subpath === "" ? required : required + "/" + subpath; // For optional segments, return the exploded path _without_ current segment first (`subpath`)
703
- // and exploded path _with_ current segment later (`subpath`)
704
- // This ensures that exploded paths are emitted in priority order
705
- // `/one/three/:four` will come before `/one/three/:five`
706
-
707
- return isOptional ? [subpath, requiredExploded] : [requiredExploded];
708
- }).map(exploded => {
709
- // for absolute paths, ensure `/` instead of empty segment
710
- return path.startsWith("/") && exploded === "" ? "/" : exploded;
711
- });
700
+ let result = []; // All child paths with the prefix. Do this for all children before the
701
+ // optional version for all children so we get consistent ordering where the
702
+ // parent optional aspect is preferred as required. Otherwise, we can get
703
+ // child sections interspersed where deeper optional segments are higher than
704
+ // parent optional segments, where for example, /:two would explodes _earlier_
705
+ // then /:one. By always including the parent as required _for all children_
706
+ // first, we avoid this issue
707
+
708
+ result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/"))); // Then if this is an optional value, add all child versions without
709
+
710
+ if (isOptional) {
711
+ result.push(...restExploded);
712
+ } // for absolute paths, ensure `/` instead of empty segment
713
+
714
+
715
+ return result.map(exploded => path.startsWith("/") && exploded === "" ? "/" : exploded);
712
716
  }
713
717
 
714
718
  function rankRouteBranches(branches) {