@jsenv/navi 0.16.3 → 0.16.4
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/jsenv_navi.js +39 -9
- package/dist/jsenv_navi.js.map +3 -3
- package/package.json +1 -1
package/dist/jsenv_navi.js
CHANGED
|
@@ -8471,6 +8471,22 @@ 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
|
+
// Parent route is a parent if child path starts with parent path
|
|
8486
|
+
// and child has additional segments
|
|
8487
|
+
return childPath.startsWith(parentPath) && childPath !== parentPath;
|
|
8488
|
+
};
|
|
8489
|
+
|
|
8474
8490
|
// Controls what happens to actions when their route stops matching:
|
|
8475
8491
|
// 'abort' - Cancel the action immediately when route stops matching
|
|
8476
8492
|
// 'keep-loading' - Allow action to continue running after route stops matching
|
|
@@ -8756,21 +8772,35 @@ const registerRoute = (routePattern) => {
|
|
|
8756
8772
|
);
|
|
8757
8773
|
}
|
|
8758
8774
|
|
|
8759
|
-
// URL -> Signal synchronization
|
|
8775
|
+
// URL -> Signal synchronization with parent-child route hierarchy checking
|
|
8760
8776
|
effect(() => {
|
|
8761
8777
|
const matching = matchingSignal.value;
|
|
8762
8778
|
const params = rawParamsSignal.value;
|
|
8763
8779
|
const urlParamValue = params[paramName];
|
|
8764
8780
|
|
|
8765
|
-
if (
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8781
|
+
if (matching) {
|
|
8782
|
+
// When route matches, sync signal with URL parameter value
|
|
8783
|
+
// This ensures URL is the source of truth
|
|
8784
|
+
stateSignal.value = urlParamValue;
|
|
8785
|
+
} else {
|
|
8786
|
+
// When route doesn't match, check if we're navigating to a parent route
|
|
8787
|
+
const currentRoutePattern = routePattern.cleanPattern;
|
|
8788
|
+
const parentRouteMatching = Array.from(routeSet).find((otherRoute) => {
|
|
8789
|
+
if (otherRoute === route || !otherRoute.matching) return false;
|
|
8790
|
+
|
|
8791
|
+
const otherRouteProperties = getRoutePrivateProperties(otherRoute);
|
|
8792
|
+
const otherPattern = otherRouteProperties.routePattern.cleanPattern;
|
|
8793
|
+
|
|
8794
|
+
// Check if the other route is a parent of this route
|
|
8795
|
+
return isParentRoute(otherPattern, currentRoutePattern);
|
|
8796
|
+
});
|
|
8797
|
+
|
|
8798
|
+
if (parentRouteMatching) {
|
|
8799
|
+
// We're navigating to a parent route - clear this signal to reflect the hierarchy
|
|
8800
|
+
const defaultValue = routePattern.parameterDefaults?.[paramName];
|
|
8801
|
+
stateSignal.value = defaultValue;
|
|
8802
|
+
}
|
|
8772
8803
|
}
|
|
8773
|
-
stateSignal.value = urlParamValue;
|
|
8774
8804
|
});
|
|
8775
8805
|
|
|
8776
8806
|
// Signal -> URL synchronization
|