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