@jsenv/navi 0.16.3 → 0.16.5

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.
@@ -8471,6 +8471,28 @@ const resolveRouteUrl = (relativeUrl) => {
8471
8471
  */
8472
8472
 
8473
8473
 
8474
+ // Helper to check if one route pattern is a parent of another
8475
+ const isParentRoute = (parentPattern, childPattern) => {
8476
+ // Normalize patterns by removing query parts and trailing slashes
8477
+ const normalizePath = (pattern) => {
8478
+ const pathPart = pattern.split("?")[0];
8479
+ return pathPart.replace(/\/$/, "") || "/";
8480
+ };
8481
+
8482
+ const parentPath = normalizePath(parentPattern);
8483
+ const childPath = normalizePath(childPattern);
8484
+
8485
+ // Special case: root route "/" should never clear signals from other routes
8486
+ // The root route is conceptually different from all other app sections
8487
+ if (parentPath === "/") {
8488
+ return false;
8489
+ }
8490
+
8491
+ // Parent route is a parent if child path starts with parent path + "/"
8492
+ // and child has additional segments
8493
+ return childPath.startsWith(`${parentPath}/`) && childPath !== parentPath;
8494
+ };
8495
+
8474
8496
  // Controls what happens to actions when their route stops matching:
8475
8497
  // 'abort' - Cancel the action immediately when route stops matching
8476
8498
  // 'keep-loading' - Allow action to continue running after route stops matching
@@ -8756,21 +8778,35 @@ const registerRoute = (routePattern) => {
8756
8778
  );
8757
8779
  }
8758
8780
 
8759
- // URL -> Signal synchronization
8781
+ // URL -> Signal synchronization with parent-child route hierarchy checking
8760
8782
  effect(() => {
8761
8783
  const matching = matchingSignal.value;
8762
8784
  const params = rawParamsSignal.value;
8763
8785
  const urlParamValue = params[paramName];
8764
8786
 
8765
- if (!matching) {
8766
- return;
8767
- }
8768
- if (debug) {
8769
- console.debug(
8770
- `[stateSignal] URL -> Signal: ${paramName}=${urlParamValue}`,
8771
- );
8787
+ if (matching) {
8788
+ // When route matches, sync signal with URL parameter value
8789
+ // This ensures URL is the source of truth
8790
+ stateSignal.value = urlParamValue;
8791
+ } else {
8792
+ // When route doesn't match, check if we're navigating to a parent route
8793
+ const currentRoutePattern = routePattern.cleanPattern;
8794
+ const parentRouteMatching = Array.from(routeSet).find((otherRoute) => {
8795
+ if (otherRoute === route || !otherRoute.matching) return false;
8796
+
8797
+ const otherRouteProperties = getRoutePrivateProperties(otherRoute);
8798
+ const otherPattern = otherRouteProperties.routePattern.cleanPattern;
8799
+
8800
+ // Check if the other route is a parent of this route
8801
+ return isParentRoute(otherPattern, currentRoutePattern);
8802
+ });
8803
+
8804
+ if (parentRouteMatching) {
8805
+ // We're navigating to a parent route - clear this signal to reflect the hierarchy
8806
+ const defaultValue = routePattern.parameterDefaults?.[paramName];
8807
+ stateSignal.value = defaultValue;
8808
+ }
8772
8809
  }
8773
- stateSignal.value = urlParamValue;
8774
8810
  });
8775
8811
 
8776
8812
  // Signal -> URL synchronization