@tanstack/router-core 0.0.1-beta.3 → 0.0.1-beta.30
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/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -2
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/{packages/router-core/src/index.js → index.js} +23 -7
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +7 -34
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +9 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/{packages/router-core/src/route.js → route.js} +15 -37
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -12
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/routeMatch.js +200 -0
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/{packages/router-core/src/router.js → router.js} +246 -208
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/{packages/router-core/src/utils.js → utils.js} +17 -30
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +382 -1307
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +161 -168
- package/build/types/index.d.ts +228 -206
- package/build/umd/index.development.js +373 -481
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/frameworks.ts +2 -2
- package/src/index.ts +0 -1
- package/src/link.ts +8 -5
- package/src/path.ts +2 -6
- package/src/qss.ts +1 -0
- package/src/route.ts +24 -32
- package/src/routeConfig.ts +100 -77
- package/src/routeInfo.ts +22 -7
- package/src/routeMatch.ts +95 -157
- package/src/router.ts +346 -122
- package/src/utils.ts +14 -7
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
|
@@ -18,14 +18,12 @@
|
|
|
18
18
|
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
19
19
|
for (var i = 1; i < arguments.length; i++) {
|
|
20
20
|
var source = arguments[i];
|
|
21
|
-
|
|
22
21
|
for (var key in source) {
|
|
23
22
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
24
23
|
target[key] = source[key];
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
return target;
|
|
30
28
|
};
|
|
31
29
|
return _extends$1.apply(this, arguments);
|
|
@@ -832,12 +830,6 @@
|
|
|
832
830
|
throw new Error(value);
|
|
833
831
|
}
|
|
834
832
|
|
|
835
|
-
// type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
836
|
-
// k: infer I,
|
|
837
|
-
// ) => any
|
|
838
|
-
// ? I
|
|
839
|
-
// : never
|
|
840
|
-
|
|
841
833
|
/**
|
|
842
834
|
* This function returns `a` if `b` is deeply equal.
|
|
843
835
|
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
@@ -847,89 +839,81 @@
|
|
|
847
839
|
if (prev === next) {
|
|
848
840
|
return prev;
|
|
849
841
|
}
|
|
850
|
-
|
|
851
842
|
const array = Array.isArray(prev) && Array.isArray(next);
|
|
852
|
-
|
|
853
843
|
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
854
844
|
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
855
845
|
const bItems = array ? next : Object.keys(next);
|
|
856
846
|
const bSize = bItems.length;
|
|
857
847
|
const copy = array ? [] : {};
|
|
858
848
|
let equalItems = 0;
|
|
859
|
-
|
|
860
849
|
for (let i = 0; i < bSize; i++) {
|
|
861
850
|
const key = array ? i : bItems[i];
|
|
862
851
|
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
863
|
-
|
|
864
852
|
if (copy[key] === prev[key]) {
|
|
865
853
|
equalItems++;
|
|
866
854
|
}
|
|
867
855
|
}
|
|
868
|
-
|
|
869
856
|
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
870
857
|
}
|
|
871
|
-
|
|
872
858
|
return next;
|
|
873
|
-
}
|
|
859
|
+
}
|
|
874
860
|
|
|
861
|
+
// Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
875
862
|
function isPlainObject(o) {
|
|
876
863
|
if (!hasObjectPrototype(o)) {
|
|
877
864
|
return false;
|
|
878
|
-
}
|
|
879
|
-
|
|
865
|
+
}
|
|
880
866
|
|
|
867
|
+
// If has modified constructor
|
|
881
868
|
const ctor = o.constructor;
|
|
882
|
-
|
|
883
869
|
if (typeof ctor === 'undefined') {
|
|
884
870
|
return true;
|
|
885
|
-
}
|
|
886
|
-
|
|
871
|
+
}
|
|
887
872
|
|
|
873
|
+
// If has modified prototype
|
|
888
874
|
const prot = ctor.prototype;
|
|
889
|
-
|
|
890
875
|
if (!hasObjectPrototype(prot)) {
|
|
891
876
|
return false;
|
|
892
|
-
}
|
|
893
|
-
|
|
877
|
+
}
|
|
894
878
|
|
|
879
|
+
// If constructor does not have an Object-specific method
|
|
895
880
|
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
896
881
|
return false;
|
|
897
|
-
}
|
|
898
|
-
|
|
882
|
+
}
|
|
899
883
|
|
|
884
|
+
// Most likely a plain Object
|
|
900
885
|
return true;
|
|
901
886
|
}
|
|
902
|
-
|
|
903
887
|
function hasObjectPrototype(o) {
|
|
904
888
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
905
889
|
}
|
|
906
|
-
|
|
907
890
|
function last(arr) {
|
|
908
891
|
return arr[arr.length - 1];
|
|
909
892
|
}
|
|
910
893
|
function warning(cond, message) {
|
|
911
894
|
if (cond) {
|
|
912
895
|
if (typeof console !== 'undefined') console.warn(message);
|
|
913
|
-
|
|
914
896
|
try {
|
|
915
897
|
throw new Error(message);
|
|
916
898
|
} catch (_unused) {}
|
|
917
899
|
}
|
|
918
|
-
|
|
919
900
|
return true;
|
|
920
901
|
}
|
|
921
|
-
|
|
922
902
|
function isFunction(d) {
|
|
923
903
|
return typeof d === 'function';
|
|
924
904
|
}
|
|
925
|
-
|
|
926
905
|
function functionalUpdate(updater, previous) {
|
|
927
906
|
if (isFunction(updater)) {
|
|
928
907
|
return updater(previous);
|
|
929
908
|
}
|
|
930
|
-
|
|
931
909
|
return updater;
|
|
932
910
|
}
|
|
911
|
+
function pick(parent, keys) {
|
|
912
|
+
return keys.reduce((obj, key) => {
|
|
913
|
+
obj[key] = parent[key];
|
|
914
|
+
return obj;
|
|
915
|
+
}, {});
|
|
916
|
+
}
|
|
933
917
|
|
|
934
918
|
function joinPaths(paths) {
|
|
935
919
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -963,12 +947,10 @@
|
|
|
963
947
|
} else ;
|
|
964
948
|
} else if (toSegment.value === '..') {
|
|
965
949
|
var _last;
|
|
966
|
-
|
|
967
950
|
// Extra trailing slash? pop it off
|
|
968
951
|
if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
|
|
969
952
|
baseSegments.pop();
|
|
970
953
|
}
|
|
971
|
-
|
|
972
954
|
baseSegments.pop();
|
|
973
955
|
} else if (toSegment.value === '.') {
|
|
974
956
|
return;
|
|
@@ -983,10 +965,8 @@
|
|
|
983
965
|
if (!pathname) {
|
|
984
966
|
return [];
|
|
985
967
|
}
|
|
986
|
-
|
|
987
968
|
pathname = cleanPath(pathname);
|
|
988
969
|
const segments = [];
|
|
989
|
-
|
|
990
970
|
if (pathname.slice(0, 1) === '/') {
|
|
991
971
|
pathname = pathname.substring(1);
|
|
992
972
|
segments.push({
|
|
@@ -994,12 +974,11 @@
|
|
|
994
974
|
value: '/'
|
|
995
975
|
});
|
|
996
976
|
}
|
|
997
|
-
|
|
998
977
|
if (!pathname) {
|
|
999
978
|
return segments;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
979
|
+
}
|
|
1002
980
|
|
|
981
|
+
// Remove empty segments and '.' segments
|
|
1003
982
|
const split = pathname.split('/').filter(Boolean);
|
|
1004
983
|
segments.push(...split.map(part => {
|
|
1005
984
|
if (part.startsWith('*')) {
|
|
@@ -1008,20 +987,17 @@
|
|
|
1008
987
|
value: part
|
|
1009
988
|
};
|
|
1010
989
|
}
|
|
1011
|
-
|
|
1012
|
-
if (part.charAt(0) === ':') {
|
|
990
|
+
if (part.charAt(0) === '$') {
|
|
1013
991
|
return {
|
|
1014
992
|
type: 'param',
|
|
1015
993
|
value: part
|
|
1016
994
|
};
|
|
1017
995
|
}
|
|
1018
|
-
|
|
1019
996
|
return {
|
|
1020
997
|
type: 'pathname',
|
|
1021
998
|
value: part
|
|
1022
999
|
};
|
|
1023
1000
|
}));
|
|
1024
|
-
|
|
1025
1001
|
if (pathname.slice(-1) === '/') {
|
|
1026
1002
|
pathname = pathname.substring(1);
|
|
1027
1003
|
segments.push({
|
|
@@ -1029,7 +1005,6 @@
|
|
|
1029
1005
|
value: '/'
|
|
1030
1006
|
});
|
|
1031
1007
|
}
|
|
1032
|
-
|
|
1033
1008
|
return segments;
|
|
1034
1009
|
}
|
|
1035
1010
|
function interpolatePath(path, params, leaveWildcard) {
|
|
@@ -1038,57 +1013,45 @@
|
|
|
1038
1013
|
if (segment.value === '*' && !leaveWildcard) {
|
|
1039
1014
|
return '';
|
|
1040
1015
|
}
|
|
1041
|
-
|
|
1042
1016
|
if (segment.type === 'param') {
|
|
1043
1017
|
var _segment$value$substr;
|
|
1044
|
-
|
|
1045
1018
|
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1046
1019
|
}
|
|
1047
|
-
|
|
1048
1020
|
return segment.value;
|
|
1049
1021
|
}));
|
|
1050
1022
|
}
|
|
1051
1023
|
function matchPathname(currentPathname, matchLocation) {
|
|
1052
|
-
const pathParams = matchByPath(currentPathname, matchLocation);
|
|
1024
|
+
const pathParams = matchByPath(currentPathname, matchLocation);
|
|
1025
|
+
// const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1053
1026
|
|
|
1054
1027
|
if (matchLocation.to && !pathParams) {
|
|
1055
1028
|
return;
|
|
1056
|
-
}
|
|
1057
|
-
// return
|
|
1058
|
-
// }
|
|
1059
|
-
|
|
1060
|
-
|
|
1029
|
+
}
|
|
1061
1030
|
return pathParams != null ? pathParams : {};
|
|
1062
1031
|
}
|
|
1063
1032
|
function matchByPath(from, matchLocation) {
|
|
1064
1033
|
var _matchLocation$to;
|
|
1065
|
-
|
|
1066
1034
|
const baseSegments = parsePathname(from);
|
|
1067
1035
|
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1068
1036
|
const params = {};
|
|
1069
|
-
|
|
1070
1037
|
let isMatch = (() => {
|
|
1071
1038
|
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1072
1039
|
const baseSegment = baseSegments[i];
|
|
1073
1040
|
const routeSegment = routeSegments[i];
|
|
1074
1041
|
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1075
1042
|
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1076
|
-
|
|
1077
1043
|
if (routeSegment) {
|
|
1078
1044
|
if (routeSegment.type === 'wildcard') {
|
|
1079
1045
|
if (baseSegment != null && baseSegment.value) {
|
|
1080
1046
|
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1081
1047
|
return true;
|
|
1082
1048
|
}
|
|
1083
|
-
|
|
1084
1049
|
return false;
|
|
1085
1050
|
}
|
|
1086
|
-
|
|
1087
1051
|
if (routeSegment.type === 'pathname') {
|
|
1088
1052
|
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1089
1053
|
return true;
|
|
1090
1054
|
}
|
|
1091
|
-
|
|
1092
1055
|
if (baseSegment) {
|
|
1093
1056
|
if (matchLocation.caseSensitive) {
|
|
1094
1057
|
if (routeSegment.value !== baseSegment.value) {
|
|
@@ -1099,41 +1062,36 @@
|
|
|
1099
1062
|
}
|
|
1100
1063
|
}
|
|
1101
1064
|
}
|
|
1102
|
-
|
|
1103
1065
|
if (!baseSegment) {
|
|
1104
1066
|
return false;
|
|
1105
1067
|
}
|
|
1106
|
-
|
|
1107
1068
|
if (routeSegment.type === 'param') {
|
|
1108
1069
|
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1109
1070
|
return false;
|
|
1110
1071
|
}
|
|
1111
|
-
|
|
1112
|
-
if (!baseSegment.value.startsWith(':')) {
|
|
1072
|
+
if (baseSegment.value.charAt(0) !== '$') {
|
|
1113
1073
|
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1114
1074
|
}
|
|
1115
1075
|
}
|
|
1116
1076
|
}
|
|
1117
|
-
|
|
1118
1077
|
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1119
1078
|
return !!matchLocation.fuzzy;
|
|
1120
1079
|
}
|
|
1121
1080
|
}
|
|
1122
|
-
|
|
1123
1081
|
return true;
|
|
1124
1082
|
})();
|
|
1125
|
-
|
|
1126
1083
|
return isMatch ? params : undefined;
|
|
1127
1084
|
}
|
|
1128
1085
|
|
|
1129
1086
|
// @ts-nocheck
|
|
1087
|
+
|
|
1130
1088
|
// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
|
|
1089
|
+
|
|
1131
1090
|
function encode(obj, pfx) {
|
|
1132
1091
|
var k,
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1092
|
+
i,
|
|
1093
|
+
tmp,
|
|
1094
|
+
str = '';
|
|
1137
1095
|
for (k in obj) {
|
|
1138
1096
|
if ((tmp = obj[k]) !== void 0) {
|
|
1139
1097
|
if (Array.isArray(tmp)) {
|
|
@@ -1147,35 +1105,30 @@
|
|
|
1147
1105
|
}
|
|
1148
1106
|
}
|
|
1149
1107
|
}
|
|
1150
|
-
|
|
1151
1108
|
return (pfx || '') + str;
|
|
1152
1109
|
}
|
|
1153
|
-
|
|
1154
1110
|
function toValue(mix) {
|
|
1155
1111
|
if (!mix) return '';
|
|
1156
1112
|
var str = decodeURIComponent(mix);
|
|
1157
1113
|
if (str === 'false') return false;
|
|
1158
1114
|
if (str === 'true') return true;
|
|
1115
|
+
if (str.charAt(0) === '0') return str;
|
|
1159
1116
|
return +str * 0 === 0 ? +str : str;
|
|
1160
1117
|
}
|
|
1161
|
-
|
|
1162
1118
|
function decode(str) {
|
|
1163
1119
|
var tmp,
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1120
|
+
k,
|
|
1121
|
+
out = {},
|
|
1122
|
+
arr = str.split('&');
|
|
1168
1123
|
while (tmp = arr.shift()) {
|
|
1169
1124
|
tmp = tmp.split('=');
|
|
1170
1125
|
k = tmp.shift();
|
|
1171
|
-
|
|
1172
1126
|
if (out[k] !== void 0) {
|
|
1173
1127
|
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
1174
1128
|
} else {
|
|
1175
1129
|
out[k] = toValue(tmp.shift());
|
|
1176
1130
|
}
|
|
1177
1131
|
}
|
|
1178
|
-
|
|
1179
1132
|
return out;
|
|
1180
1133
|
}
|
|
1181
1134
|
|
|
@@ -1183,14 +1136,12 @@
|
|
|
1183
1136
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1184
1137
|
for (var i = 1; i < arguments.length; i++) {
|
|
1185
1138
|
var source = arguments[i];
|
|
1186
|
-
|
|
1187
1139
|
for (var key in source) {
|
|
1188
1140
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1189
1141
|
target[key] = source[key];
|
|
1190
1142
|
}
|
|
1191
1143
|
}
|
|
1192
1144
|
}
|
|
1193
|
-
|
|
1194
1145
|
return target;
|
|
1195
1146
|
};
|
|
1196
1147
|
return _extends.apply(this, arguments);
|
|
@@ -1203,36 +1154,31 @@
|
|
|
1203
1154
|
path: routePath,
|
|
1204
1155
|
fullPath
|
|
1205
1156
|
} = routeConfig;
|
|
1206
|
-
|
|
1207
1157
|
const action = router.state.actions[id] || (() => {
|
|
1208
1158
|
router.state.actions[id] = {
|
|
1209
|
-
|
|
1159
|
+
submissions: [],
|
|
1210
1160
|
submit: async (submission, actionOpts) => {
|
|
1211
1161
|
var _actionOpts$invalidat;
|
|
1212
|
-
|
|
1213
1162
|
if (!route) {
|
|
1214
1163
|
return;
|
|
1215
1164
|
}
|
|
1216
|
-
|
|
1217
1165
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1166
|
+
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1167
|
+
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1168
|
+
}
|
|
1218
1169
|
const actionState = {
|
|
1219
1170
|
submittedAt: Date.now(),
|
|
1220
1171
|
status: 'pending',
|
|
1221
|
-
submission
|
|
1172
|
+
submission,
|
|
1173
|
+
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1222
1174
|
};
|
|
1223
1175
|
action.current = actionState;
|
|
1224
1176
|
action.latest = actionState;
|
|
1225
|
-
action.
|
|
1226
|
-
router.state = _extends({}, router.state, {
|
|
1227
|
-
currentAction: actionState,
|
|
1228
|
-
latestAction: actionState
|
|
1229
|
-
});
|
|
1177
|
+
action.submissions.push(actionState);
|
|
1230
1178
|
router.notify();
|
|
1231
|
-
|
|
1232
1179
|
try {
|
|
1233
1180
|
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
1234
1181
|
actionState.data = res;
|
|
1235
|
-
|
|
1236
1182
|
if (invalidate) {
|
|
1237
1183
|
router.invalidateRoute({
|
|
1238
1184
|
to: '.',
|
|
@@ -1240,26 +1186,20 @@
|
|
|
1240
1186
|
});
|
|
1241
1187
|
await router.reload();
|
|
1242
1188
|
}
|
|
1243
|
-
|
|
1244
1189
|
actionState.status = 'success';
|
|
1245
1190
|
return res;
|
|
1246
1191
|
} catch (err) {
|
|
1192
|
+
console.log('tanner');
|
|
1247
1193
|
console.error(err);
|
|
1248
1194
|
actionState.error = err;
|
|
1249
1195
|
actionState.status = 'error';
|
|
1250
1196
|
} finally {
|
|
1251
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1252
|
-
router.removeActionQueue.push({
|
|
1253
|
-
action,
|
|
1254
|
-
actionState
|
|
1255
|
-
});
|
|
1256
1197
|
router.notify();
|
|
1257
1198
|
}
|
|
1258
1199
|
}
|
|
1259
1200
|
};
|
|
1260
1201
|
return router.state.actions[id];
|
|
1261
1202
|
})();
|
|
1262
|
-
|
|
1263
1203
|
const loader = router.state.loaders[id] || (() => {
|
|
1264
1204
|
router.state.loaders[id] = {
|
|
1265
1205
|
pending: [],
|
|
@@ -1267,34 +1207,34 @@
|
|
|
1267
1207
|
if (!route) {
|
|
1268
1208
|
return;
|
|
1269
1209
|
}
|
|
1270
|
-
|
|
1271
1210
|
const loaderState = {
|
|
1272
1211
|
loadedAt: Date.now(),
|
|
1273
1212
|
loaderContext
|
|
1274
1213
|
};
|
|
1275
1214
|
loader.current = loaderState;
|
|
1276
1215
|
loader.latest = loaderState;
|
|
1277
|
-
loader.pending.push(loaderState);
|
|
1216
|
+
loader.pending.push(loaderState);
|
|
1217
|
+
|
|
1218
|
+
// router.state = {
|
|
1278
1219
|
// ...router.state,
|
|
1279
1220
|
// currentAction: loaderState,
|
|
1280
1221
|
// latestAction: loaderState,
|
|
1281
1222
|
// }
|
|
1282
1223
|
|
|
1283
1224
|
router.notify();
|
|
1284
|
-
|
|
1285
1225
|
try {
|
|
1286
1226
|
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
1287
1227
|
} finally {
|
|
1288
|
-
loader.pending = loader.pending.filter(d => d !== loaderState);
|
|
1289
|
-
|
|
1228
|
+
loader.pending = loader.pending.filter(d => d !== loaderState);
|
|
1229
|
+
// router.removeActionQueue.push({ loader, loaderState })
|
|
1290
1230
|
router.notify();
|
|
1291
1231
|
}
|
|
1292
1232
|
}
|
|
1293
1233
|
};
|
|
1294
1234
|
return router.state.loaders[id];
|
|
1295
1235
|
})();
|
|
1296
|
-
|
|
1297
1236
|
let route = {
|
|
1237
|
+
routeInfo: undefined,
|
|
1298
1238
|
routeId: id,
|
|
1299
1239
|
routeRouteId: routeId,
|
|
1300
1240
|
routePath,
|
|
@@ -1327,52 +1267,37 @@
|
|
|
1327
1267
|
});
|
|
1328
1268
|
return route;
|
|
1329
1269
|
}
|
|
1330
|
-
function cascadeLoaderData(matches) {
|
|
1331
|
-
matches.forEach((match, index) => {
|
|
1332
|
-
const parent = matches[index - 1];
|
|
1333
|
-
|
|
1334
|
-
if (parent) {
|
|
1335
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
1270
|
|
|
1340
1271
|
const rootRouteId = '__root__';
|
|
1341
1272
|
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
1342
1273
|
if (options === void 0) {
|
|
1343
1274
|
options = {};
|
|
1344
1275
|
}
|
|
1345
|
-
|
|
1346
1276
|
if (isRoot === void 0) {
|
|
1347
1277
|
isRoot = true;
|
|
1348
1278
|
}
|
|
1349
|
-
|
|
1350
1279
|
if (isRoot) {
|
|
1351
1280
|
options.path = rootRouteId;
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1281
|
+
}
|
|
1354
1282
|
|
|
1283
|
+
// Strip the root from parentIds
|
|
1355
1284
|
if (parentId === rootRouteId) {
|
|
1356
1285
|
parentId = '';
|
|
1357
1286
|
}
|
|
1287
|
+
let path = isRoot ? rootRouteId : options.path;
|
|
1358
1288
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1289
|
+
// If the path is anything other than an index path, trim it up
|
|
1361
1290
|
if (path && path !== '/') {
|
|
1362
1291
|
path = trimPath(path);
|
|
1363
1292
|
}
|
|
1364
|
-
|
|
1365
1293
|
const routeId = path || options.id;
|
|
1366
1294
|
let id = joinPaths([parentId, routeId]);
|
|
1367
|
-
|
|
1368
1295
|
if (path === rootRouteId) {
|
|
1369
1296
|
path = '/';
|
|
1370
1297
|
}
|
|
1371
|
-
|
|
1372
1298
|
if (id !== rootRouteId) {
|
|
1373
1299
|
id = joinPaths(['/', id]);
|
|
1374
1300
|
}
|
|
1375
|
-
|
|
1376
1301
|
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
1377
1302
|
return {
|
|
1378
1303
|
id: id,
|
|
@@ -1381,13 +1306,15 @@
|
|
|
1381
1306
|
fullPath: fullPath,
|
|
1382
1307
|
options: options,
|
|
1383
1308
|
children,
|
|
1384
|
-
createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
|
|
1385
1309
|
addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
|
|
1386
|
-
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
|
|
1310
|
+
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
|
|
1311
|
+
generate: () => {
|
|
1312
|
+
invariant(false, "routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. ");
|
|
1313
|
+
}
|
|
1387
1314
|
};
|
|
1388
1315
|
};
|
|
1389
1316
|
|
|
1390
|
-
const
|
|
1317
|
+
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1391
1318
|
function createRouteMatch(router, route, opts) {
|
|
1392
1319
|
const routeMatch = _extends({}, route, opts, {
|
|
1393
1320
|
router,
|
|
@@ -1397,10 +1324,10 @@
|
|
|
1397
1324
|
status: 'idle',
|
|
1398
1325
|
routeLoaderData: {},
|
|
1399
1326
|
loaderData: {},
|
|
1400
|
-
isPending: false,
|
|
1401
1327
|
isFetching: false,
|
|
1402
1328
|
isInvalid: false,
|
|
1403
1329
|
invalidAt: Infinity,
|
|
1330
|
+
// pendingActions: [],
|
|
1404
1331
|
getIsInvalid: () => {
|
|
1405
1332
|
const now = Date.now();
|
|
1406
1333
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1411,63 +1338,30 @@
|
|
|
1411
1338
|
resolve: () => {},
|
|
1412
1339
|
notify: () => {
|
|
1413
1340
|
routeMatch.__.resolve();
|
|
1414
|
-
|
|
1415
1341
|
routeMatch.router.notify();
|
|
1416
1342
|
},
|
|
1417
|
-
startPending: () => {
|
|
1418
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
1419
|
-
|
|
1420
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
1421
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
1422
|
-
|
|
1423
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
1424
|
-
return;
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
1428
|
-
routeMatch.isPending = true;
|
|
1429
|
-
|
|
1430
|
-
routeMatch.__.resolve();
|
|
1431
|
-
|
|
1432
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
1433
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
1434
|
-
}
|
|
1435
|
-
}, pendingMs);
|
|
1436
|
-
},
|
|
1437
|
-
cancelPending: () => {
|
|
1438
|
-
routeMatch.isPending = false;
|
|
1439
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
1440
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1441
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1442
|
-
},
|
|
1443
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1444
|
-
// routeMatch.parentMatch = parentMatch
|
|
1445
|
-
// },
|
|
1446
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1447
|
-
// if (
|
|
1448
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1449
|
-
// ) {
|
|
1450
|
-
// return
|
|
1451
|
-
// }
|
|
1452
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1453
|
-
// },
|
|
1454
1343
|
validate: () => {
|
|
1455
1344
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1456
|
-
|
|
1457
1345
|
// Validate the search params and stabilize them
|
|
1458
1346
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1459
|
-
|
|
1460
1347
|
try {
|
|
1348
|
+
var _validator;
|
|
1461
1349
|
const prevSearch = routeMatch.routeSearch;
|
|
1462
1350
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1463
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch))
|
|
1351
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
|
|
1464
1352
|
|
|
1353
|
+
// Invalidate route matches when search param stability changes
|
|
1465
1354
|
if (prevSearch !== nextSearch) {
|
|
1466
1355
|
routeMatch.isInvalid = true;
|
|
1467
1356
|
}
|
|
1468
|
-
|
|
1469
1357
|
routeMatch.routeSearch = nextSearch;
|
|
1470
1358
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1359
|
+
componentTypes.map(async type => {
|
|
1360
|
+
const component = routeMatch.options[type];
|
|
1361
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1362
|
+
routeMatch.__[type] = component;
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1471
1365
|
} catch (err) {
|
|
1472
1366
|
console.error(err);
|
|
1473
1367
|
const error = new Error('Invalid search params found', {
|
|
@@ -1475,162 +1369,129 @@
|
|
|
1475
1369
|
});
|
|
1476
1370
|
error.code = 'INVALID_SEARCH_PARAMS';
|
|
1477
1371
|
routeMatch.status = 'error';
|
|
1478
|
-
routeMatch.error = error;
|
|
1479
|
-
|
|
1372
|
+
routeMatch.error = error;
|
|
1373
|
+
// Do not proceed with loading the route
|
|
1480
1374
|
return;
|
|
1481
1375
|
}
|
|
1482
1376
|
}
|
|
1483
1377
|
},
|
|
1484
1378
|
cancel: () => {
|
|
1485
1379
|
var _routeMatch$__$abortC;
|
|
1486
|
-
|
|
1487
1380
|
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1488
|
-
|
|
1489
|
-
routeMatch.__.cancelPending();
|
|
1490
1381
|
},
|
|
1491
1382
|
invalidate: () => {
|
|
1492
1383
|
routeMatch.isInvalid = true;
|
|
1493
1384
|
},
|
|
1494
1385
|
hasLoaders: () => {
|
|
1495
|
-
return !!(route.options.loader ||
|
|
1386
|
+
return !!(route.options.loader || componentTypes.some(d => {
|
|
1387
|
+
var _route$options$d;
|
|
1388
|
+
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1389
|
+
}));
|
|
1496
1390
|
},
|
|
1497
1391
|
load: async loaderOpts => {
|
|
1498
1392
|
const now = Date.now();
|
|
1499
|
-
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
1393
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
1500
1394
|
|
|
1395
|
+
// If this is a preload, add it to the preload cache
|
|
1501
1396
|
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1502
1397
|
// If the match is currently active, don't preload it
|
|
1503
1398
|
if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1504
1399
|
return;
|
|
1505
1400
|
}
|
|
1506
|
-
|
|
1507
1401
|
router.matchCache[routeMatch.matchId] = {
|
|
1508
1402
|
gc: now + loaderOpts.gcMaxAge,
|
|
1509
1403
|
match: routeMatch
|
|
1510
1404
|
};
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1405
|
+
}
|
|
1513
1406
|
|
|
1407
|
+
// If the match is invalid, errored or idle, trigger it to load
|
|
1514
1408
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1515
1409
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1516
|
-
routeMatch.fetch({
|
|
1410
|
+
await routeMatch.fetch({
|
|
1517
1411
|
maxAge
|
|
1518
1412
|
});
|
|
1519
1413
|
}
|
|
1520
1414
|
},
|
|
1521
1415
|
fetch: async opts => {
|
|
1522
|
-
const
|
|
1523
|
-
routeMatch.__.latestId =
|
|
1416
|
+
const loadId = '' + Date.now() + Math.random();
|
|
1417
|
+
routeMatch.__.latestId = loadId;
|
|
1418
|
+
const checkLatest = async () => {
|
|
1419
|
+
if (loadId !== routeMatch.__.latestId) {
|
|
1420
|
+
// warning(true, 'Data loader is out of date!')
|
|
1421
|
+
return new Promise(() => {});
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
// If the match was in an error state, set it
|
|
1524
1426
|
// to a loading state again. Otherwise, keep it
|
|
1525
1427
|
// as loading or resolved
|
|
1526
|
-
|
|
1527
1428
|
if (routeMatch.status === 'idle') {
|
|
1528
1429
|
routeMatch.status = 'loading';
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1430
|
+
}
|
|
1531
1431
|
|
|
1432
|
+
// We started loading the route, so it's no longer invalid
|
|
1532
1433
|
routeMatch.isInvalid = false;
|
|
1533
1434
|
routeMatch.__.loadPromise = new Promise(async resolve => {
|
|
1534
1435
|
// We are now fetching, even if it's in the background of a
|
|
1535
1436
|
// resolved state
|
|
1536
1437
|
routeMatch.isFetching = true;
|
|
1537
1438
|
routeMatch.__.resolve = resolve;
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
//
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
if (routeMatch.__[type]) {
|
|
1548
|
-
return;
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1552
|
-
}));
|
|
1553
|
-
})();
|
|
1554
|
-
|
|
1555
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1556
|
-
try {
|
|
1557
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1558
|
-
|
|
1559
|
-
if (routeMatch.options.loader) {
|
|
1560
|
-
const data = await routeMatch.options.loader({
|
|
1561
|
-
params: routeMatch.params,
|
|
1562
|
-
search: routeMatch.routeSearch,
|
|
1563
|
-
signal: routeMatch.__.abortController.signal
|
|
1564
|
-
});
|
|
1565
|
-
|
|
1566
|
-
if (id !== routeMatch.__.latestId) {
|
|
1567
|
-
return routeMatch.__.loaderPromise;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
routeMatch.error = undefined;
|
|
1574
|
-
routeMatch.status = 'success';
|
|
1575
|
-
routeMatch.updatedAt = Date.now();
|
|
1576
|
-
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1577
|
-
} catch (err) {
|
|
1578
|
-
if (id !== routeMatch.__.latestId) {
|
|
1579
|
-
return routeMatch.__.loaderPromise;
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
{
|
|
1583
|
-
console.error(err);
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
routeMatch.error = err;
|
|
1587
|
-
routeMatch.status = 'error';
|
|
1588
|
-
routeMatch.updatedAt = Date.now();
|
|
1439
|
+
routeMatch.__.componentsPromise = (async () => {
|
|
1440
|
+
// then run all component and data loaders in parallel
|
|
1441
|
+
// For each component type, potentially load it asynchronously
|
|
1442
|
+
|
|
1443
|
+
await Promise.all(componentTypes.map(async type => {
|
|
1444
|
+
var _routeMatch$__$type;
|
|
1445
|
+
const component = routeMatch.options[type];
|
|
1446
|
+
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1447
|
+
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1589
1448
|
}
|
|
1590
|
-
});
|
|
1591
|
-
|
|
1449
|
+
}));
|
|
1450
|
+
})();
|
|
1451
|
+
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1592
1452
|
try {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1453
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1454
|
+
if (routeMatch.options.loader) {
|
|
1455
|
+
const data = await router.loadMatchData(routeMatch);
|
|
1456
|
+
await checkLatest();
|
|
1457
|
+
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1597
1458
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1459
|
+
routeMatch.error = undefined;
|
|
1460
|
+
routeMatch.status = 'success';
|
|
1461
|
+
routeMatch.updatedAt = Date.now();
|
|
1462
|
+
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1463
|
+
return routeMatch.routeLoaderData;
|
|
1464
|
+
} catch (err) {
|
|
1465
|
+
await checkLatest();
|
|
1466
|
+
{
|
|
1467
|
+
console.error(err);
|
|
1606
1468
|
}
|
|
1607
|
-
|
|
1608
|
-
routeMatch.
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
routeMatch.isFetching = false;
|
|
1612
|
-
|
|
1613
|
-
routeMatch.__.notify();
|
|
1469
|
+
routeMatch.error = err;
|
|
1470
|
+
routeMatch.status = 'error';
|
|
1471
|
+
routeMatch.updatedAt = Date.now();
|
|
1472
|
+
throw err;
|
|
1614
1473
|
}
|
|
1615
|
-
})
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1474
|
+
});
|
|
1475
|
+
const after = async () => {
|
|
1476
|
+
await checkLatest();
|
|
1477
|
+
routeMatch.isFetching = false;
|
|
1478
|
+
delete routeMatch.__.loadPromise;
|
|
1479
|
+
routeMatch.__.notify();
|
|
1480
|
+
};
|
|
1481
|
+
try {
|
|
1482
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1483
|
+
after();
|
|
1484
|
+
} catch (_unused) {
|
|
1485
|
+
after();
|
|
1622
1486
|
}
|
|
1623
|
-
|
|
1624
|
-
delete routeMatch.__.loaderPromise;
|
|
1625
1487
|
});
|
|
1626
|
-
|
|
1488
|
+
await routeMatch.__.loadPromise;
|
|
1489
|
+
await checkLatest();
|
|
1627
1490
|
}
|
|
1628
1491
|
});
|
|
1629
|
-
|
|
1630
1492
|
if (!routeMatch.hasLoaders()) {
|
|
1631
1493
|
routeMatch.status = 'success';
|
|
1632
1494
|
}
|
|
1633
|
-
|
|
1634
1495
|
return routeMatch;
|
|
1635
1496
|
}
|
|
1636
1497
|
|
|
@@ -1641,42 +1502,39 @@
|
|
|
1641
1502
|
if (searchStr.substring(0, 1) === '?') {
|
|
1642
1503
|
searchStr = searchStr.substring(1);
|
|
1643
1504
|
}
|
|
1505
|
+
let query = decode(searchStr);
|
|
1644
1506
|
|
|
1645
|
-
|
|
1646
|
-
|
|
1507
|
+
// Try to parse any query params that might be json
|
|
1647
1508
|
for (let key in query) {
|
|
1648
1509
|
const value = query[key];
|
|
1649
|
-
|
|
1650
1510
|
if (typeof value === 'string') {
|
|
1651
1511
|
try {
|
|
1652
1512
|
query[key] = parser(value);
|
|
1653
|
-
} catch (err) {
|
|
1513
|
+
} catch (err) {
|
|
1514
|
+
//
|
|
1654
1515
|
}
|
|
1655
1516
|
}
|
|
1656
1517
|
}
|
|
1657
|
-
|
|
1658
1518
|
return query;
|
|
1659
1519
|
};
|
|
1660
1520
|
}
|
|
1661
1521
|
function stringifySearchWith(stringify) {
|
|
1662
1522
|
return search => {
|
|
1663
1523
|
search = _extends({}, search);
|
|
1664
|
-
|
|
1665
1524
|
if (search) {
|
|
1666
1525
|
Object.keys(search).forEach(key => {
|
|
1667
1526
|
const val = search[key];
|
|
1668
|
-
|
|
1669
1527
|
if (typeof val === 'undefined' || val === undefined) {
|
|
1670
1528
|
delete search[key];
|
|
1671
1529
|
} else if (val && typeof val === 'object' && val !== null) {
|
|
1672
1530
|
try {
|
|
1673
1531
|
search[key] = stringify(val);
|
|
1674
|
-
} catch (err) {
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
// silent
|
|
1675
1534
|
}
|
|
1676
1535
|
}
|
|
1677
1536
|
});
|
|
1678
1537
|
}
|
|
1679
|
-
|
|
1680
1538
|
const searchStr = encode(search).toString();
|
|
1681
1539
|
return searchStr ? "?" + searchStr : '';
|
|
1682
1540
|
};
|
|
@@ -1684,50 +1542,53 @@
|
|
|
1684
1542
|
|
|
1685
1543
|
var _window$document;
|
|
1686
1544
|
// Detect if we're in the DOM
|
|
1687
|
-
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
1545
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
1688
1546
|
|
|
1547
|
+
// This is the default history object if none is defined
|
|
1689
1548
|
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1690
|
-
|
|
1549
|
+
function getInitialRouterState() {
|
|
1550
|
+
return {
|
|
1551
|
+
status: 'idle',
|
|
1552
|
+
location: null,
|
|
1553
|
+
matches: [],
|
|
1554
|
+
actions: {},
|
|
1555
|
+
loaders: {},
|
|
1556
|
+
lastUpdated: Date.now(),
|
|
1557
|
+
isFetching: false,
|
|
1558
|
+
isPreloading: false
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1691
1561
|
function createRouter(userOptions) {
|
|
1692
1562
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
1693
|
-
|
|
1694
1563
|
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
1695
|
-
|
|
1696
1564
|
const originalOptions = _extends({
|
|
1697
1565
|
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1698
1566
|
defaultLoaderMaxAge: 0,
|
|
1699
1567
|
defaultPreloadMaxAge: 2000,
|
|
1700
|
-
defaultPreloadDelay: 50
|
|
1568
|
+
defaultPreloadDelay: 50,
|
|
1569
|
+
context: undefined
|
|
1701
1570
|
}, userOptions, {
|
|
1702
1571
|
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1703
1572
|
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
1704
1573
|
});
|
|
1705
|
-
|
|
1706
1574
|
let router = {
|
|
1575
|
+
types: undefined,
|
|
1576
|
+
// public api
|
|
1707
1577
|
history,
|
|
1708
1578
|
options: originalOptions,
|
|
1709
1579
|
listeners: [],
|
|
1710
|
-
removeActionQueue: [],
|
|
1711
1580
|
// Resolved after construction
|
|
1712
1581
|
basepath: '',
|
|
1713
1582
|
routeTree: undefined,
|
|
1714
1583
|
routesById: {},
|
|
1715
1584
|
location: undefined,
|
|
1716
|
-
allRouteInfo: undefined,
|
|
1717
1585
|
//
|
|
1718
|
-
navigationPromise: Promise.resolve(),
|
|
1719
1586
|
resolveNavigation: () => {},
|
|
1720
1587
|
matchCache: {},
|
|
1721
|
-
state:
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
actions: {},
|
|
1726
|
-
loaders: {},
|
|
1727
|
-
loaderData: {},
|
|
1728
|
-
lastUpdated: Date.now(),
|
|
1729
|
-
isFetching: false,
|
|
1730
|
-
isPreloading: false
|
|
1588
|
+
state: getInitialRouterState(),
|
|
1589
|
+
reset: () => {
|
|
1590
|
+
router.state = getInitialRouterState();
|
|
1591
|
+
router.notify();
|
|
1731
1592
|
},
|
|
1732
1593
|
startedLoadingAt: Date.now(),
|
|
1733
1594
|
subscribe: listener => {
|
|
@@ -1740,62 +1601,104 @@
|
|
|
1740
1601
|
return router.routesById[id];
|
|
1741
1602
|
},
|
|
1742
1603
|
notify: () => {
|
|
1743
|
-
router.state
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1604
|
+
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1605
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1606
|
+
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1607
|
+
router.state = _extends({}, router.state, {
|
|
1608
|
+
isFetching,
|
|
1609
|
+
isPreloading
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1747
1612
|
cascadeLoaderData(router.state.matches);
|
|
1748
1613
|
router.listeners.forEach(listener => listener(router));
|
|
1749
1614
|
},
|
|
1615
|
+
dehydrate: () => {
|
|
1616
|
+
return {
|
|
1617
|
+
location: router.location,
|
|
1618
|
+
state: _extends({}, pick(router.state, ['status', 'location', 'lastUpdated', 'location']), {
|
|
1619
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1620
|
+
}),
|
|
1621
|
+
context: router.options.context
|
|
1622
|
+
};
|
|
1623
|
+
},
|
|
1624
|
+
hydrate: dehydratedState => {
|
|
1625
|
+
// Update the location
|
|
1626
|
+
router.location = dehydratedState.location;
|
|
1627
|
+
|
|
1628
|
+
// Update the context
|
|
1629
|
+
router.options.context = dehydratedState.context;
|
|
1630
|
+
|
|
1631
|
+
// Match the routes
|
|
1632
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1633
|
+
strictParseParams: true
|
|
1634
|
+
});
|
|
1635
|
+
matches.forEach((match, index) => {
|
|
1636
|
+
const dehydratedMatch = dehydratedState.state.matches[index];
|
|
1637
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1638
|
+
Object.assign(match, dehydratedMatch);
|
|
1639
|
+
});
|
|
1640
|
+
matches.forEach(match => match.__.validate());
|
|
1641
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1642
|
+
matches
|
|
1643
|
+
});
|
|
1644
|
+
},
|
|
1750
1645
|
mount: () => {
|
|
1751
1646
|
const next = router.__.buildLocation({
|
|
1752
1647
|
to: '.',
|
|
1753
1648
|
search: true,
|
|
1754
1649
|
hash: true
|
|
1755
|
-
});
|
|
1756
|
-
// to the current location. Otherwise, load the current location.
|
|
1757
|
-
|
|
1650
|
+
});
|
|
1758
1651
|
|
|
1652
|
+
// If the current location isn't updated, trigger a navigation
|
|
1653
|
+
// to the current location. Otherwise, load the current location.
|
|
1759
1654
|
if (next.href !== router.location.href) {
|
|
1760
1655
|
router.__.commitLocation(next, true);
|
|
1761
|
-
} else {
|
|
1762
|
-
router.loadLocation();
|
|
1763
1656
|
}
|
|
1657
|
+
if (!router.state.matches.length) {
|
|
1658
|
+
router.load();
|
|
1659
|
+
}
|
|
1660
|
+
const unsub = router.history.listen(event => {
|
|
1661
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1662
|
+
});
|
|
1764
1663
|
|
|
1765
|
-
|
|
1766
|
-
router.loadLocation(router.__.parseLocation(event.location, router.location));
|
|
1767
|
-
}); // addEventListener does not exist in React Native, but window does
|
|
1664
|
+
// addEventListener does not exist in React Native, but window does
|
|
1768
1665
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1769
|
-
|
|
1770
1666
|
if (!isServer && window.addEventListener) {
|
|
1771
1667
|
// Listen to visibillitychange and focus
|
|
1772
1668
|
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
1773
1669
|
window.addEventListener('focus', router.onFocus, false);
|
|
1774
1670
|
}
|
|
1775
|
-
|
|
1776
1671
|
return () => {
|
|
1777
|
-
unsub();
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1672
|
+
unsub();
|
|
1673
|
+
if (!isServer && window.removeEventListener) {
|
|
1674
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1675
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1676
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1677
|
+
}
|
|
1781
1678
|
};
|
|
1782
1679
|
},
|
|
1783
1680
|
onFocus: () => {
|
|
1784
|
-
router.
|
|
1681
|
+
router.load();
|
|
1785
1682
|
},
|
|
1786
1683
|
update: opts => {
|
|
1684
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1685
|
+
if (!router.location || newHistory) {
|
|
1686
|
+
if (opts != null && opts.history) {
|
|
1687
|
+
router.history = opts.history;
|
|
1688
|
+
}
|
|
1689
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1690
|
+
router.state.location = router.location;
|
|
1691
|
+
}
|
|
1787
1692
|
Object.assign(router.options, opts);
|
|
1788
1693
|
const {
|
|
1789
1694
|
basepath,
|
|
1790
1695
|
routeConfig
|
|
1791
1696
|
} = router.options;
|
|
1792
1697
|
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
1793
|
-
|
|
1794
1698
|
if (routeConfig) {
|
|
1795
1699
|
router.routesById = {};
|
|
1796
1700
|
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
1797
1701
|
}
|
|
1798
|
-
|
|
1799
1702
|
return router;
|
|
1800
1703
|
},
|
|
1801
1704
|
cancelMatches: () => {
|
|
@@ -1804,58 +1707,60 @@
|
|
|
1804
1707
|
match.cancel();
|
|
1805
1708
|
});
|
|
1806
1709
|
},
|
|
1807
|
-
|
|
1710
|
+
load: async next => {
|
|
1808
1711
|
const id = Math.random();
|
|
1809
1712
|
router.startedLoadingAt = id;
|
|
1810
|
-
|
|
1811
1713
|
if (next) {
|
|
1812
1714
|
// Ingest the new location
|
|
1813
1715
|
router.location = next;
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1818
|
-
let {
|
|
1819
|
-
action,
|
|
1820
|
-
actionState
|
|
1821
|
-
} = _ref;
|
|
1822
|
-
|
|
1823
|
-
if (router.state.currentAction === actionState) {
|
|
1824
|
-
router.state.currentAction = undefined;
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
if (action.current === actionState) {
|
|
1828
|
-
action.current = undefined;
|
|
1829
|
-
}
|
|
1830
|
-
});
|
|
1831
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1716
|
+
}
|
|
1832
1717
|
|
|
1833
|
-
|
|
1718
|
+
// Cancel any pending matches
|
|
1719
|
+
router.cancelMatches();
|
|
1834
1720
|
|
|
1835
|
-
|
|
1721
|
+
// Match the routes
|
|
1722
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1836
1723
|
strictParseParams: true
|
|
1837
1724
|
});
|
|
1838
|
-
|
|
1839
|
-
|
|
1725
|
+
if (typeof document !== 'undefined') {
|
|
1726
|
+
router.state = _extends({}, router.state, {
|
|
1727
|
+
pending: {
|
|
1728
|
+
matches: matches,
|
|
1729
|
+
location: router.location
|
|
1730
|
+
},
|
|
1731
|
+
status: 'loading'
|
|
1732
|
+
});
|
|
1733
|
+
} else {
|
|
1734
|
+
router.state = _extends({}, router.state, {
|
|
1840
1735
|
matches: matches,
|
|
1841
|
-
location: router.location
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
}
|
|
1845
|
-
router.notify(); // Load the matches
|
|
1736
|
+
location: router.location,
|
|
1737
|
+
status: 'loading'
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1846
1740
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1741
|
+
// Check if each match middleware to see if the route can be accessed
|
|
1742
|
+
try {
|
|
1743
|
+
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1744
|
+
router: router,
|
|
1745
|
+
match
|
|
1746
|
+
})));
|
|
1747
|
+
} catch (err) {
|
|
1748
|
+
if (err != null && err.then) {
|
|
1749
|
+
await new Promise(() => {});
|
|
1750
|
+
}
|
|
1751
|
+
throw err;
|
|
1752
|
+
}
|
|
1753
|
+
router.notify();
|
|
1850
1754
|
|
|
1755
|
+
// Load the matches
|
|
1756
|
+
await router.loadMatches(matches);
|
|
1851
1757
|
if (router.startedLoadingAt !== id) {
|
|
1852
1758
|
// Ignore side-effects of match loading
|
|
1853
1759
|
return router.navigationPromise;
|
|
1854
1760
|
}
|
|
1855
|
-
|
|
1856
1761
|
const previousMatches = router.state.matches;
|
|
1857
1762
|
const exiting = [],
|
|
1858
|
-
|
|
1763
|
+
staying = [];
|
|
1859
1764
|
previousMatches.forEach(d => {
|
|
1860
1765
|
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
1861
1766
|
staying.push(d);
|
|
@@ -1863,22 +1768,23 @@
|
|
|
1863
1768
|
exiting.push(d);
|
|
1864
1769
|
}
|
|
1865
1770
|
});
|
|
1771
|
+
const entering = matches.filter(d => {
|
|
1772
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1773
|
+
});
|
|
1866
1774
|
const now = Date.now();
|
|
1867
1775
|
exiting.forEach(d => {
|
|
1868
|
-
var
|
|
1869
|
-
|
|
1776
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1870
1777
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1871
1778
|
params: d.params,
|
|
1872
1779
|
search: d.routeSearch
|
|
1873
|
-
});
|
|
1780
|
+
});
|
|
1874
1781
|
|
|
1782
|
+
// Clear idle error states when match leaves
|
|
1875
1783
|
if (d.status === 'error' && !d.isFetching) {
|
|
1876
1784
|
d.status = 'idle';
|
|
1877
1785
|
d.error = undefined;
|
|
1878
1786
|
}
|
|
1879
|
-
|
|
1880
|
-
const gc = Math.max((_ref2 = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref2 : 0, (_ref3 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0);
|
|
1881
|
-
|
|
1787
|
+
const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
|
|
1882
1788
|
if (gc > 0) {
|
|
1883
1789
|
router.matchCache[d.matchId] = {
|
|
1884
1790
|
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
@@ -1892,27 +1798,24 @@
|
|
|
1892
1798
|
search: d.routeSearch
|
|
1893
1799
|
});
|
|
1894
1800
|
});
|
|
1895
|
-
const entering = matches.filter(d => {
|
|
1896
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1897
|
-
});
|
|
1898
1801
|
entering.forEach(d => {
|
|
1899
|
-
d.__.onExit = d.options.
|
|
1802
|
+
d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
|
|
1900
1803
|
params: d.params,
|
|
1901
1804
|
search: d.search
|
|
1902
1805
|
});
|
|
1903
1806
|
delete router.matchCache[d.matchId];
|
|
1904
1807
|
});
|
|
1905
|
-
|
|
1906
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1907
|
-
router.notify();
|
|
1908
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
1808
|
if (router.startedLoadingAt !== id) {
|
|
1912
1809
|
// Ignore side-effects of match loading
|
|
1913
1810
|
return;
|
|
1914
1811
|
}
|
|
1915
|
-
|
|
1812
|
+
matches.forEach(match => {
|
|
1813
|
+
// Clear actions
|
|
1814
|
+
if (match.action) {
|
|
1815
|
+
match.action.current = undefined;
|
|
1816
|
+
match.action.submissions = [];
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1916
1819
|
router.state = _extends({}, router.state, {
|
|
1917
1820
|
location: router.location,
|
|
1918
1821
|
matches,
|
|
@@ -1925,18 +1828,19 @@
|
|
|
1925
1828
|
cleanMatchCache: () => {
|
|
1926
1829
|
const now = Date.now();
|
|
1927
1830
|
Object.keys(router.matchCache).forEach(matchId => {
|
|
1928
|
-
const entry = router.matchCache[matchId];
|
|
1831
|
+
const entry = router.matchCache[matchId];
|
|
1929
1832
|
|
|
1833
|
+
// Don't remove loading matches
|
|
1930
1834
|
if (entry.match.status === 'loading') {
|
|
1931
1835
|
return;
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1836
|
+
}
|
|
1934
1837
|
|
|
1838
|
+
// Do not remove successful matches that are still valid
|
|
1935
1839
|
if (entry.gc > 0 && entry.gc > now) {
|
|
1936
1840
|
return;
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1841
|
+
}
|
|
1939
1842
|
|
|
1843
|
+
// Everything else gets removed
|
|
1940
1844
|
delete router.matchCache[matchId];
|
|
1941
1845
|
});
|
|
1942
1846
|
},
|
|
@@ -1944,7 +1848,6 @@
|
|
|
1944
1848
|
if (navigateOpts === void 0) {
|
|
1945
1849
|
navigateOpts = router.location;
|
|
1946
1850
|
}
|
|
1947
|
-
|
|
1948
1851
|
const next = router.buildNext(navigateOpts);
|
|
1949
1852
|
const matches = router.matchRoutes(next.pathname, {
|
|
1950
1853
|
strictParseParams: true
|
|
@@ -1953,108 +1856,87 @@
|
|
|
1953
1856
|
return matches;
|
|
1954
1857
|
},
|
|
1955
1858
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1956
|
-
var
|
|
1957
|
-
|
|
1859
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1958
1860
|
if (navigateOpts === void 0) {
|
|
1959
1861
|
navigateOpts = router.location;
|
|
1960
1862
|
}
|
|
1961
|
-
|
|
1962
1863
|
const next = router.buildNext(navigateOpts);
|
|
1963
1864
|
const matches = router.matchRoutes(next.pathname, {
|
|
1964
1865
|
strictParseParams: true
|
|
1965
1866
|
});
|
|
1966
1867
|
await router.loadMatches(matches, {
|
|
1967
1868
|
preload: true,
|
|
1968
|
-
maxAge: (
|
|
1969
|
-
gcMaxAge: (
|
|
1869
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
1870
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
1970
1871
|
});
|
|
1971
1872
|
return matches;
|
|
1972
1873
|
},
|
|
1973
1874
|
matchRoutes: (pathname, opts) => {
|
|
1974
1875
|
var _router$state$pending3, _router$state$pending4;
|
|
1975
|
-
|
|
1976
1876
|
router.cleanMatchCache();
|
|
1977
1877
|
const matches = [];
|
|
1978
|
-
|
|
1979
1878
|
if (!router.routeTree) {
|
|
1980
1879
|
return matches;
|
|
1981
1880
|
}
|
|
1982
|
-
|
|
1983
1881
|
const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
|
|
1984
|
-
|
|
1985
1882
|
const recurse = async routes => {
|
|
1986
1883
|
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1987
|
-
|
|
1988
1884
|
const parentMatch = last(matches);
|
|
1989
1885
|
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1990
1886
|
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1991
1887
|
let foundRoutes = [];
|
|
1992
|
-
|
|
1993
1888
|
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1994
1889
|
routes.some(route => {
|
|
1995
1890
|
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
1996
|
-
|
|
1997
1891
|
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
1998
1892
|
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
1999
1893
|
}
|
|
2000
|
-
|
|
2001
1894
|
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
2002
1895
|
const matchParams = matchPathname(pathname, {
|
|
2003
1896
|
to: route.fullPath,
|
|
2004
1897
|
fuzzy,
|
|
2005
1898
|
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
2006
1899
|
});
|
|
2007
|
-
|
|
2008
1900
|
if (matchParams) {
|
|
2009
1901
|
let parsedParams;
|
|
2010
|
-
|
|
2011
1902
|
try {
|
|
2012
1903
|
var _route$options$parseP;
|
|
2013
|
-
|
|
2014
1904
|
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
2015
1905
|
} catch (err) {
|
|
2016
1906
|
if (opts != null && opts.strictParseParams) {
|
|
2017
1907
|
throw err;
|
|
2018
1908
|
}
|
|
2019
1909
|
}
|
|
2020
|
-
|
|
2021
1910
|
params = _extends({}, params, parsedParams);
|
|
2022
1911
|
}
|
|
2023
|
-
|
|
2024
1912
|
if (!!matchParams) {
|
|
2025
1913
|
foundRoutes = [...parentRoutes, route];
|
|
2026
1914
|
}
|
|
2027
|
-
|
|
2028
1915
|
return !!foundRoutes.length;
|
|
2029
1916
|
});
|
|
2030
1917
|
return !!foundRoutes.length;
|
|
2031
1918
|
};
|
|
2032
|
-
|
|
2033
1919
|
findMatchInRoutes([], filteredRoutes);
|
|
2034
|
-
|
|
2035
1920
|
if (!foundRoutes.length) {
|
|
2036
1921
|
return;
|
|
2037
1922
|
}
|
|
2038
|
-
|
|
2039
1923
|
foundRoutes.forEach(foundRoute => {
|
|
2040
1924
|
var _router$matchCache$ma;
|
|
2041
|
-
|
|
2042
1925
|
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2043
1926
|
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2044
1927
|
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
1928
|
+
parentMatch,
|
|
2045
1929
|
matchId,
|
|
2046
1930
|
params,
|
|
2047
|
-
pathname: joinPaths([
|
|
1931
|
+
pathname: joinPaths([router.basepath, interpolatedPath])
|
|
2048
1932
|
});
|
|
2049
1933
|
matches.push(match);
|
|
2050
1934
|
});
|
|
2051
1935
|
const foundRoute = last(foundRoutes);
|
|
2052
|
-
|
|
2053
1936
|
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
2054
1937
|
recurse(foundRoute.childRoutes);
|
|
2055
1938
|
}
|
|
2056
1939
|
};
|
|
2057
|
-
|
|
2058
1940
|
recurse([router.routeTree]);
|
|
2059
1941
|
cascadeLoaderData(matches);
|
|
2060
1942
|
return matches;
|
|
@@ -2063,23 +1945,61 @@
|
|
|
2063
1945
|
const matchPromises = resolvedMatches.map(async match => {
|
|
2064
1946
|
// Validate the match (loads search params etc)
|
|
2065
1947
|
match.__.validate();
|
|
2066
|
-
|
|
2067
1948
|
match.load(loaderOpts);
|
|
2068
|
-
|
|
2069
|
-
if (
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
1949
|
+
const search = match.search;
|
|
1950
|
+
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
if (match.__.loadPromise) {
|
|
1954
|
+
// Wait for the first sign of activity from the match
|
|
2074
1955
|
await match.__.loadPromise;
|
|
2075
1956
|
}
|
|
2076
1957
|
});
|
|
2077
1958
|
router.notify();
|
|
2078
1959
|
await Promise.all(matchPromises);
|
|
2079
1960
|
},
|
|
1961
|
+
loadMatchData: async routeMatch => {
|
|
1962
|
+
if (isServer || !router.options.useServerData) {
|
|
1963
|
+
var _await$routeMatch$opt;
|
|
1964
|
+
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
1965
|
+
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
1966
|
+
params: routeMatch.params,
|
|
1967
|
+
search: routeMatch.routeSearch,
|
|
1968
|
+
signal: routeMatch.__.abortController.signal
|
|
1969
|
+
}))) != null ? _await$routeMatch$opt : {};
|
|
1970
|
+
} else {
|
|
1971
|
+
const next = router.buildNext({
|
|
1972
|
+
to: '.',
|
|
1973
|
+
search: d => _extends({}, d != null ? d : {}, {
|
|
1974
|
+
__data: {
|
|
1975
|
+
matchId: routeMatch.matchId
|
|
1976
|
+
}
|
|
1977
|
+
})
|
|
1978
|
+
});
|
|
1979
|
+
|
|
1980
|
+
// Refresh:
|
|
1981
|
+
// '/dashboard'
|
|
1982
|
+
// '/dashboard/invoices/'
|
|
1983
|
+
// '/dashboard/invoices/123'
|
|
1984
|
+
|
|
1985
|
+
// New:
|
|
1986
|
+
// '/dashboard/invoices/456'
|
|
1987
|
+
|
|
1988
|
+
// TODO: batch requests when possible
|
|
1989
|
+
|
|
1990
|
+
const res = await fetch(next.href, {
|
|
1991
|
+
method: 'GET'
|
|
1992
|
+
// signal: routeMatch.__.abortController.signal,
|
|
1993
|
+
});
|
|
1994
|
+
|
|
1995
|
+
if (res.ok) {
|
|
1996
|
+
return res.json();
|
|
1997
|
+
}
|
|
1998
|
+
throw new Error('Failed to fetch match data');
|
|
1999
|
+
}
|
|
2000
|
+
},
|
|
2080
2001
|
invalidateRoute: opts => {
|
|
2081
2002
|
var _router$state$pending5, _router$state$pending6;
|
|
2082
|
-
|
|
2083
2003
|
const next = router.buildNext(opts);
|
|
2084
2004
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2085
2005
|
[...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
|
|
@@ -2098,30 +2018,26 @@
|
|
|
2098
2018
|
},
|
|
2099
2019
|
matchRoute: (location, opts) => {
|
|
2100
2020
|
var _location$from;
|
|
2101
|
-
|
|
2102
2021
|
// const location = router.buildNext(opts)
|
|
2022
|
+
|
|
2103
2023
|
location = _extends({}, location, {
|
|
2104
2024
|
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
2105
2025
|
});
|
|
2106
2026
|
const next = router.buildNext(location);
|
|
2107
|
-
|
|
2108
2027
|
if (opts != null && opts.pending) {
|
|
2109
2028
|
var _router$state$pending7;
|
|
2110
|
-
|
|
2111
2029
|
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2112
2030
|
return false;
|
|
2113
2031
|
}
|
|
2114
|
-
|
|
2115
2032
|
return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
|
|
2116
2033
|
to: next.pathname
|
|
2117
2034
|
}));
|
|
2118
2035
|
}
|
|
2119
|
-
|
|
2120
2036
|
return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
|
|
2121
2037
|
to: next.pathname
|
|
2122
2038
|
}));
|
|
2123
2039
|
},
|
|
2124
|
-
navigate: async
|
|
2040
|
+
navigate: async _ref7 => {
|
|
2125
2041
|
let {
|
|
2126
2042
|
from,
|
|
2127
2043
|
to = '.',
|
|
@@ -2129,20 +2045,19 @@
|
|
|
2129
2045
|
hash,
|
|
2130
2046
|
replace,
|
|
2131
2047
|
params
|
|
2132
|
-
} =
|
|
2048
|
+
} = _ref7;
|
|
2133
2049
|
// If this link simply reloads the current route,
|
|
2134
2050
|
// make sure it has a new key so it will trigger a data refresh
|
|
2051
|
+
|
|
2135
2052
|
// If this `to` is a valid external URL, return
|
|
2136
2053
|
// null for LinkUtils
|
|
2137
2054
|
const toString = String(to);
|
|
2138
2055
|
const fromString = String(from);
|
|
2139
2056
|
let isExternal;
|
|
2140
|
-
|
|
2141
2057
|
try {
|
|
2142
2058
|
new URL("" + toString);
|
|
2143
2059
|
isExternal = true;
|
|
2144
2060
|
} catch (e) {}
|
|
2145
|
-
|
|
2146
2061
|
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
2147
2062
|
return router.__.navigate({
|
|
2148
2063
|
from: fromString,
|
|
@@ -2153,9 +2068,8 @@
|
|
|
2153
2068
|
params
|
|
2154
2069
|
});
|
|
2155
2070
|
},
|
|
2156
|
-
buildLink:
|
|
2157
|
-
var _preload,
|
|
2158
|
-
|
|
2071
|
+
buildLink: _ref8 => {
|
|
2072
|
+
var _preload, _ref9;
|
|
2159
2073
|
let {
|
|
2160
2074
|
from,
|
|
2161
2075
|
to = '.',
|
|
@@ -2170,12 +2084,13 @@
|
|
|
2170
2084
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2171
2085
|
preloadDelay: userPreloadDelay,
|
|
2172
2086
|
disabled
|
|
2173
|
-
} =
|
|
2174
|
-
|
|
2087
|
+
} = _ref8;
|
|
2175
2088
|
// If this link simply reloads the current route,
|
|
2176
2089
|
// make sure it has a new key so it will trigger a data refresh
|
|
2090
|
+
|
|
2177
2091
|
// If this `to` is a valid external URL, return
|
|
2178
2092
|
// null for LinkUtils
|
|
2093
|
+
|
|
2179
2094
|
try {
|
|
2180
2095
|
new URL("" + to);
|
|
2181
2096
|
return {
|
|
@@ -2183,7 +2098,6 @@
|
|
|
2183
2098
|
href: to
|
|
2184
2099
|
};
|
|
2185
2100
|
} catch (e) {}
|
|
2186
|
-
|
|
2187
2101
|
const nextOpts = {
|
|
2188
2102
|
from,
|
|
2189
2103
|
to,
|
|
@@ -2194,33 +2108,35 @@
|
|
|
2194
2108
|
};
|
|
2195
2109
|
const next = router.buildNext(nextOpts);
|
|
2196
2110
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2197
|
-
const preloadDelay = (
|
|
2111
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
2198
2112
|
|
|
2113
|
+
// Compare path/hash for matches
|
|
2199
2114
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2200
2115
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
2201
2116
|
const nextPathSplit = next.pathname.split('/');
|
|
2202
2117
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2203
|
-
const hashIsEqual = router.state.location.hash === next.hash;
|
|
2204
|
-
|
|
2118
|
+
const hashIsEqual = router.state.location.hash === next.hash;
|
|
2119
|
+
// Combine the matches based on user options
|
|
2205
2120
|
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2206
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
2121
|
+
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
2207
2122
|
|
|
2208
|
-
|
|
2123
|
+
// The final "active" test
|
|
2124
|
+
const isActive = pathTest && hashTest;
|
|
2209
2125
|
|
|
2126
|
+
// The click handler
|
|
2210
2127
|
const handleClick = e => {
|
|
2211
2128
|
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2212
2129
|
e.preventDefault();
|
|
2213
|
-
|
|
2214
2130
|
if (pathIsEqual && !search && !hash) {
|
|
2215
2131
|
router.invalidateRoute(nextOpts);
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2132
|
+
}
|
|
2218
2133
|
|
|
2134
|
+
// All is well? Navigate!)
|
|
2219
2135
|
router.__.navigate(nextOpts);
|
|
2220
2136
|
}
|
|
2221
|
-
};
|
|
2222
|
-
|
|
2137
|
+
};
|
|
2223
2138
|
|
|
2139
|
+
// The click handler
|
|
2224
2140
|
const handleFocus = e => {
|
|
2225
2141
|
if (preload) {
|
|
2226
2142
|
router.preloadRoute(nextOpts, {
|
|
@@ -2229,15 +2145,12 @@
|
|
|
2229
2145
|
});
|
|
2230
2146
|
}
|
|
2231
2147
|
};
|
|
2232
|
-
|
|
2233
2148
|
const handleEnter = e => {
|
|
2234
2149
|
const target = e.target || {};
|
|
2235
|
-
|
|
2236
2150
|
if (preload) {
|
|
2237
2151
|
if (target.preloadTimeout) {
|
|
2238
2152
|
return;
|
|
2239
2153
|
}
|
|
2240
|
-
|
|
2241
2154
|
target.preloadTimeout = setTimeout(() => {
|
|
2242
2155
|
target.preloadTimeout = null;
|
|
2243
2156
|
router.preloadRoute(nextOpts, {
|
|
@@ -2247,16 +2160,13 @@
|
|
|
2247
2160
|
}, preloadDelay);
|
|
2248
2161
|
}
|
|
2249
2162
|
};
|
|
2250
|
-
|
|
2251
2163
|
const handleLeave = e => {
|
|
2252
2164
|
const target = e.target || {};
|
|
2253
|
-
|
|
2254
2165
|
if (target.preloadTimeout) {
|
|
2255
2166
|
clearTimeout(target.preloadTimeout);
|
|
2256
2167
|
target.preloadTimeout = null;
|
|
2257
2168
|
}
|
|
2258
2169
|
};
|
|
2259
|
-
|
|
2260
2170
|
return {
|
|
2261
2171
|
type: 'internal',
|
|
2262
2172
|
next,
|
|
@@ -2270,21 +2180,15 @@
|
|
|
2270
2180
|
},
|
|
2271
2181
|
buildNext: opts => {
|
|
2272
2182
|
const next = router.__.buildLocation(opts);
|
|
2273
|
-
|
|
2274
2183
|
const matches = router.matchRoutes(next.pathname);
|
|
2275
|
-
|
|
2276
2184
|
const __preSearchFilters = matches.map(match => {
|
|
2277
2185
|
var _match$options$preSea;
|
|
2278
|
-
|
|
2279
2186
|
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
2280
2187
|
}).flat().filter(Boolean);
|
|
2281
|
-
|
|
2282
2188
|
const __postSearchFilters = matches.map(match => {
|
|
2283
2189
|
var _match$options$postSe;
|
|
2284
|
-
|
|
2285
2190
|
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
2286
2191
|
}).flat().filter(Boolean);
|
|
2287
|
-
|
|
2288
2192
|
return router.__.buildLocation(_extends({}, opts, {
|
|
2289
2193
|
__preSearchFilters,
|
|
2290
2194
|
__postSearchFilters
|
|
@@ -2295,18 +2199,12 @@
|
|
|
2295
2199
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2296
2200
|
return routeConfigs.map(routeConfig => {
|
|
2297
2201
|
const routeOptions = routeConfig.options;
|
|
2298
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2299
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2300
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2301
|
-
// }
|
|
2302
|
-
|
|
2202
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2303
2203
|
const existingRoute = router.routesById[route.routeId];
|
|
2304
|
-
|
|
2305
2204
|
if (existingRoute) {
|
|
2306
2205
|
{
|
|
2307
2206
|
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
2308
2207
|
}
|
|
2309
|
-
|
|
2310
2208
|
throw new Error();
|
|
2311
2209
|
}
|
|
2312
2210
|
router.routesById[route.routeId] = route;
|
|
@@ -2315,13 +2213,11 @@
|
|
|
2315
2213
|
return route;
|
|
2316
2214
|
});
|
|
2317
2215
|
};
|
|
2318
|
-
|
|
2319
2216
|
const routes = recurseRoutes([rootRouteConfig]);
|
|
2320
2217
|
return routes[0];
|
|
2321
2218
|
},
|
|
2322
2219
|
parseLocation: (location, previousLocation) => {
|
|
2323
2220
|
var _location$hash$split$;
|
|
2324
|
-
|
|
2325
2221
|
const parsedSearch = router.options.parseSearch(location.search);
|
|
2326
2222
|
return {
|
|
2327
2223
|
pathname: location.pathname,
|
|
@@ -2339,41 +2235,36 @@
|
|
|
2339
2235
|
},
|
|
2340
2236
|
buildLocation: function buildLocation(dest) {
|
|
2341
2237
|
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
2342
|
-
|
|
2343
2238
|
if (dest === void 0) {
|
|
2344
2239
|
dest = {};
|
|
2345
2240
|
}
|
|
2346
|
-
|
|
2347
2241
|
// const resolvedFrom: Location = {
|
|
2348
2242
|
// ...router.location,
|
|
2349
2243
|
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
2350
|
-
|
|
2351
2244
|
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2352
|
-
|
|
2353
2245
|
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
2354
2246
|
strictParseParams: true
|
|
2355
2247
|
});
|
|
2356
2248
|
const toMatches = router.matchRoutes(pathname);
|
|
2357
|
-
|
|
2358
2249
|
const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
2359
|
-
|
|
2360
2250
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
2361
|
-
|
|
2362
2251
|
if (nextParams) {
|
|
2363
2252
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
2364
2253
|
Object.assign({}, nextParams, fn(nextParams));
|
|
2365
2254
|
});
|
|
2366
2255
|
}
|
|
2256
|
+
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
|
|
2367
2257
|
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
|
|
2258
|
+
// Pre filters first
|
|
2259
|
+
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search;
|
|
2371
2260
|
|
|
2261
|
+
// Then the link/navigate function
|
|
2372
2262
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
2373
2263
|
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
2374
2264
|
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
2375
|
-
: {};
|
|
2265
|
+
: {};
|
|
2376
2266
|
|
|
2267
|
+
// Then post filters
|
|
2377
2268
|
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2378
2269
|
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
2379
2270
|
const searchStr = router.options.stringifySearch(search);
|
|
@@ -2393,25 +2284,21 @@
|
|
|
2393
2284
|
const id = '' + Date.now() + Math.random();
|
|
2394
2285
|
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
2395
2286
|
let nextAction = 'replace';
|
|
2396
|
-
|
|
2397
2287
|
if (!replace) {
|
|
2398
2288
|
nextAction = 'push';
|
|
2399
2289
|
}
|
|
2400
|
-
|
|
2401
2290
|
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
2402
|
-
|
|
2403
2291
|
if (isSameUrl && !next.key) {
|
|
2404
2292
|
nextAction = 'replace';
|
|
2405
2293
|
}
|
|
2406
|
-
|
|
2407
2294
|
if (nextAction === 'replace') {
|
|
2408
2295
|
history.replace({
|
|
2409
2296
|
pathname: next.pathname,
|
|
2410
2297
|
hash: next.hash,
|
|
2411
2298
|
search: next.searchStr
|
|
2412
|
-
}, {
|
|
2299
|
+
}, _extends({
|
|
2413
2300
|
id
|
|
2414
|
-
});
|
|
2301
|
+
}, next.state));
|
|
2415
2302
|
} else {
|
|
2416
2303
|
history.push({
|
|
2417
2304
|
pathname: next.pathname,
|
|
@@ -2421,32 +2308,36 @@
|
|
|
2421
2308
|
id
|
|
2422
2309
|
});
|
|
2423
2310
|
}
|
|
2424
|
-
|
|
2425
2311
|
router.navigationPromise = new Promise(resolve => {
|
|
2426
2312
|
const previousNavigationResolve = router.resolveNavigation;
|
|
2427
|
-
|
|
2428
2313
|
router.resolveNavigation = () => {
|
|
2429
2314
|
previousNavigationResolve();
|
|
2430
2315
|
resolve();
|
|
2316
|
+
delete router.navigationPromise;
|
|
2431
2317
|
};
|
|
2432
2318
|
});
|
|
2433
2319
|
return router.navigationPromise;
|
|
2434
2320
|
}
|
|
2435
2321
|
}
|
|
2436
2322
|
};
|
|
2437
|
-
router.
|
|
2438
|
-
router.state.location = router.location;
|
|
2439
|
-
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2323
|
+
router.update(userOptions);
|
|
2440
2324
|
|
|
2325
|
+
// Allow frameworks to hook into the router creation
|
|
2441
2326
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
2442
2327
|
return router;
|
|
2443
2328
|
}
|
|
2444
|
-
|
|
2445
2329
|
function isCtrlEvent(e) {
|
|
2446
2330
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2447
2331
|
}
|
|
2332
|
+
function cascadeLoaderData(matches) {
|
|
2333
|
+
matches.forEach((match, index) => {
|
|
2334
|
+
const parent = matches[index - 1];
|
|
2335
|
+
if (parent) {
|
|
2336
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2448
2340
|
|
|
2449
|
-
exports.cascadeLoaderData = cascadeLoaderData;
|
|
2450
2341
|
exports.cleanPath = cleanPath;
|
|
2451
2342
|
exports.createBrowserHistory = createBrowserHistory;
|
|
2452
2343
|
exports.createHashHistory = createHashHistory;
|
|
@@ -2468,6 +2359,7 @@
|
|
|
2468
2359
|
exports.matchPathname = matchPathname;
|
|
2469
2360
|
exports.parsePathname = parsePathname;
|
|
2470
2361
|
exports.parseSearchWith = parseSearchWith;
|
|
2362
|
+
exports.pick = pick;
|
|
2471
2363
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2472
2364
|
exports.resolvePath = resolvePath;
|
|
2473
2365
|
exports.rootRouteId = rootRouteId;
|