@remix-run/router 1.9.0-pre.0 → 1.9.0-pre.2
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 +16 -0
- package/dist/history.d.ts +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +32 -44
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -9
- package/dist/router.js +24 -26
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +32 -44
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +16 -8
- package/history.ts +8 -5
- package/index.ts +2 -0
- package/package.json +1 -1
- package/router.ts +4 -27
- package/utils.ts +48 -16
package/dist/router.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.9.0-pre.
|
|
2
|
+
* @remix-run/router v1.9.0-pre.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -47,25 +47,23 @@
|
|
|
47
47
|
* The pathname, search, and hash values of a URL.
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
|
+
// TODO: (v7) Change the Location generic default from `any` to `unknown` and
|
|
51
|
+
// remove Remix `useLocation` wrapper.
|
|
50
52
|
/**
|
|
51
53
|
* An entry in a history stack. A location contains information about the
|
|
52
54
|
* URL path, as well as possibly some arbitrary state and a key.
|
|
53
55
|
*/
|
|
54
|
-
|
|
55
56
|
/**
|
|
56
57
|
* A change to the current location.
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
59
|
/**
|
|
60
60
|
* A function that receives notifications about location changes.
|
|
61
61
|
*/
|
|
62
|
-
|
|
63
62
|
/**
|
|
64
63
|
* Describes a location that is the destination of some navigation, either via
|
|
65
|
-
* `history.push` or `history.replace`.
|
|
66
|
-
* URL path.
|
|
64
|
+
* `history.push` or `history.replace`. This may be either a URL or the pieces
|
|
65
|
+
* of a URL path.
|
|
67
66
|
*/
|
|
68
|
-
|
|
69
67
|
/**
|
|
70
68
|
* A history is an interface to the navigation stack. The history serves as the
|
|
71
69
|
* source of truth for the current location, as well as provides a set of
|
|
@@ -74,7 +72,6 @@
|
|
|
74
72
|
* It is similar to the DOM's `window.history` object, but with a smaller, more
|
|
75
73
|
* focused API.
|
|
76
74
|
*/
|
|
77
|
-
|
|
78
75
|
const PopStateEventType = "popstate";
|
|
79
76
|
//#endregion
|
|
80
77
|
|
|
@@ -327,7 +324,7 @@
|
|
|
327
324
|
try {
|
|
328
325
|
// Welcome to debugging history!
|
|
329
326
|
//
|
|
330
|
-
// This error is thrown as a convenience so you can more easily
|
|
327
|
+
// This error is thrown as a convenience, so you can more easily
|
|
331
328
|
// find the source for a warning that appears in the console by
|
|
332
329
|
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
333
330
|
throw new Error(message);
|
|
@@ -607,32 +604,29 @@
|
|
|
607
604
|
* this as a private implementation detail in case they diverge in the future.
|
|
608
605
|
*/
|
|
609
606
|
|
|
607
|
+
// TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
|
|
608
|
+
// ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
|
|
609
|
+
// Also, make them a type alias instead of an interface
|
|
610
610
|
/**
|
|
611
611
|
* Arguments passed to loader functions
|
|
612
612
|
*/
|
|
613
|
-
|
|
614
613
|
/**
|
|
615
614
|
* Arguments passed to action functions
|
|
616
615
|
*/
|
|
617
|
-
|
|
618
616
|
/**
|
|
619
617
|
* Loaders and actions can return anything except `undefined` (`null` is a
|
|
620
618
|
* valid return value if there is no data to return). Responses are preferred
|
|
621
619
|
* and will ease any future migration to Remix
|
|
622
620
|
*/
|
|
623
|
-
|
|
624
621
|
/**
|
|
625
622
|
* Route loader function signature
|
|
626
623
|
*/
|
|
627
|
-
|
|
628
624
|
/**
|
|
629
625
|
* Route action function signature
|
|
630
626
|
*/
|
|
631
|
-
|
|
632
627
|
/**
|
|
633
628
|
* Arguments passed to shouldRevalidate function
|
|
634
629
|
*/
|
|
635
|
-
|
|
636
630
|
/**
|
|
637
631
|
* Route shouldRevalidate function signature. This runs after any submission
|
|
638
632
|
* (navigation or fetcher), so we flatten the navigation/fetcher submission
|
|
@@ -640,25 +634,21 @@
|
|
|
640
634
|
* or a fetcher, what really matters is the URLs and the formData since loaders
|
|
641
635
|
* have to re-run based on the data models that were potentially mutated.
|
|
642
636
|
*/
|
|
643
|
-
|
|
644
637
|
/**
|
|
645
638
|
* Function provided by the framework-aware layers to set `hasErrorBoundary`
|
|
646
639
|
* from the framework-aware `errorElement` prop
|
|
647
640
|
*
|
|
648
641
|
* @deprecated Use `mapRouteProperties` instead
|
|
649
642
|
*/
|
|
650
|
-
|
|
651
643
|
/**
|
|
652
644
|
* Function provided by the framework-aware layers to set any framework-specific
|
|
653
645
|
* properties from framework-agnostic properties
|
|
654
646
|
*/
|
|
655
|
-
|
|
656
647
|
/**
|
|
657
648
|
* Keys we cannot change from within a lazy() function. We spread all other keys
|
|
658
649
|
* onto the route. Either they're meaningful to the router, or they'll get
|
|
659
650
|
* ignored.
|
|
660
651
|
*/
|
|
661
|
-
|
|
662
652
|
const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
|
|
663
653
|
|
|
664
654
|
/**
|
|
@@ -700,7 +690,7 @@
|
|
|
700
690
|
*/
|
|
701
691
|
|
|
702
692
|
// Attempt to parse the given string segment. If it fails, then just return the
|
|
703
|
-
// plain string type as a default fallback. Otherwise return the union of the
|
|
693
|
+
// plain string type as a default fallback. Otherwise, return the union of the
|
|
704
694
|
// parsed string literals that were referenced as dynamic segments in the route.
|
|
705
695
|
/**
|
|
706
696
|
* The parameters that were parsed from the URL path.
|
|
@@ -712,7 +702,7 @@
|
|
|
712
702
|
return route.index === true;
|
|
713
703
|
}
|
|
714
704
|
|
|
715
|
-
// Walk the route tree generating unique IDs where necessary so we are working
|
|
705
|
+
// Walk the route tree generating unique IDs where necessary, so we are working
|
|
716
706
|
// solely with AgnosticDataRouteObject's within the Router
|
|
717
707
|
function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath, manifest) {
|
|
718
708
|
if (parentPath === void 0) {
|
|
@@ -775,6 +765,20 @@
|
|
|
775
765
|
}
|
|
776
766
|
return matches;
|
|
777
767
|
}
|
|
768
|
+
function convertRouteMatchToUiMatch(match, loaderData) {
|
|
769
|
+
let {
|
|
770
|
+
route,
|
|
771
|
+
pathname,
|
|
772
|
+
params
|
|
773
|
+
} = match;
|
|
774
|
+
return {
|
|
775
|
+
id: route.id,
|
|
776
|
+
pathname,
|
|
777
|
+
params,
|
|
778
|
+
data: loaderData[route.id],
|
|
779
|
+
handle: route.handle
|
|
780
|
+
};
|
|
781
|
+
}
|
|
778
782
|
function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
779
783
|
if (branches === void 0) {
|
|
780
784
|
branches = [];
|
|
@@ -799,7 +803,7 @@
|
|
|
799
803
|
let path = joinPaths([parentPath, meta.relativePath]);
|
|
800
804
|
let routesMeta = parentsMeta.concat(meta);
|
|
801
805
|
|
|
802
|
-
// Add the children before adding this route to the array so we traverse the
|
|
806
|
+
// Add the children before adding this route to the array, so we traverse the
|
|
803
807
|
// route tree depth-first and child routes appear before their parents in
|
|
804
808
|
// the "flattened" version.
|
|
805
809
|
if (route.children && route.children.length > 0) {
|
|
@@ -867,15 +871,15 @@
|
|
|
867
871
|
let result = [];
|
|
868
872
|
|
|
869
873
|
// All child paths with the prefix. Do this for all children before the
|
|
870
|
-
// optional version for all children so we get consistent ordering where the
|
|
874
|
+
// optional version for all children, so we get consistent ordering where the
|
|
871
875
|
// parent optional aspect is preferred as required. Otherwise, we can get
|
|
872
876
|
// child sections interspersed where deeper optional segments are higher than
|
|
873
|
-
// parent optional segments, where for example, /:two would
|
|
877
|
+
// parent optional segments, where for example, /:two would explode _earlier_
|
|
874
878
|
// then /:one. By always including the parent as required _for all children_
|
|
875
879
|
// first, we avoid this issue
|
|
876
880
|
result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/")));
|
|
877
881
|
|
|
878
|
-
// Then if this is an optional value, add all child versions without
|
|
882
|
+
// Then, if this is an optional value, add all child versions without
|
|
879
883
|
if (isOptional) {
|
|
880
884
|
result.push(...restExploded);
|
|
881
885
|
}
|
|
@@ -1063,7 +1067,7 @@
|
|
|
1063
1067
|
regexpSource += "\\/*$";
|
|
1064
1068
|
} else if (path !== "" && path !== "/") {
|
|
1065
1069
|
// If our path is non-empty and contains anything beyond an initial slash,
|
|
1066
|
-
// then we have _some_ form of path in our regex so we should expect to
|
|
1070
|
+
// then we have _some_ form of path in our regex, so we should expect to
|
|
1067
1071
|
// match only if we find the end of this path segment. Look for an optional
|
|
1068
1072
|
// non-captured trailing slash (to match a portion of the URL) or the end
|
|
1069
1073
|
// of the path (if we've matched to the end). We used to do this with a
|
|
@@ -2974,7 +2978,7 @@
|
|
|
2974
2978
|
}
|
|
2975
2979
|
function getScrollKey(location, matches) {
|
|
2976
2980
|
if (getScrollRestorationKey) {
|
|
2977
|
-
let key = getScrollRestorationKey(location, matches.map(m =>
|
|
2981
|
+
let key = getScrollRestorationKey(location, matches.map(m => convertRouteMatchToUiMatch(m, state.loaderData)));
|
|
2978
2982
|
return key || location.key;
|
|
2979
2983
|
}
|
|
2980
2984
|
return location.key;
|
|
@@ -4379,23 +4383,6 @@
|
|
|
4379
4383
|
function hasNakedIndexQuery(search) {
|
|
4380
4384
|
return new URLSearchParams(search).getAll("index").some(v => v === "");
|
|
4381
4385
|
}
|
|
4382
|
-
|
|
4383
|
-
// Note: This should match the format exported by useMatches, so if you change
|
|
4384
|
-
// this please also change that :) Eventually we'll DRY this up
|
|
4385
|
-
function createUseMatchesMatch(match, loaderData) {
|
|
4386
|
-
let {
|
|
4387
|
-
route,
|
|
4388
|
-
pathname,
|
|
4389
|
-
params
|
|
4390
|
-
} = match;
|
|
4391
|
-
return {
|
|
4392
|
-
id: route.id,
|
|
4393
|
-
pathname,
|
|
4394
|
-
params,
|
|
4395
|
-
data: loaderData[route.id],
|
|
4396
|
-
handle: route.handle
|
|
4397
|
-
};
|
|
4398
|
-
}
|
|
4399
4386
|
function getTargetMatch(matches, location) {
|
|
4400
4387
|
let search = typeof location === "string" ? parsePath(location).search : location.search;
|
|
4401
4388
|
if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
|
@@ -4551,6 +4538,7 @@
|
|
|
4551
4538
|
exports.UNSAFE_DEFERRED_SYMBOL = UNSAFE_DEFERRED_SYMBOL;
|
|
4552
4539
|
exports.UNSAFE_DeferredData = DeferredData;
|
|
4553
4540
|
exports.UNSAFE_ErrorResponseImpl = ErrorResponseImpl;
|
|
4541
|
+
exports.UNSAFE_convertRouteMatchToUiMatch = convertRouteMatchToUiMatch;
|
|
4554
4542
|
exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
|
|
4555
4543
|
exports.UNSAFE_getPathContributingMatches = getPathContributingMatches;
|
|
4556
4544
|
exports.UNSAFE_invariant = invariant;
|