@tanstack/react-router 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.
@@ -38,56 +38,39 @@
38
38
  _extends$2 = Object.assign ? Object.assign.bind() : function (target) {
39
39
  for (var i = 1; i < arguments.length; i++) {
40
40
  var source = arguments[i];
41
-
42
41
  for (var key in source) {
43
42
  if (Object.prototype.hasOwnProperty.call(source, key)) {
44
43
  target[key] = source[key];
45
44
  }
46
45
  }
47
46
  }
48
-
49
47
  return target;
50
48
  };
51
49
  return _extends$2.apply(this, arguments);
52
50
  }
53
-
54
51
  function _objectWithoutPropertiesLoose(source, excluded) {
55
52
  if (source == null) return {};
56
53
  var target = {};
57
54
  var sourceKeys = Object.keys(source);
58
55
  var key, i;
59
-
60
56
  for (i = 0; i < sourceKeys.length; i++) {
61
57
  key = sourceKeys[i];
62
58
  if (excluded.indexOf(key) >= 0) continue;
63
59
  target[key] = source[key];
64
60
  }
65
-
66
61
  return target;
67
62
  }
68
63
 
69
- /**
70
- * router-core
71
- *
72
- * Copyright (c) TanStack
73
- *
74
- * This source code is licensed under the MIT license found in the
75
- * LICENSE.md file in the root directory of this source tree.
76
- *
77
- * @license MIT
78
- */
79
64
  function _extends$1() {
80
65
  _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
81
66
  for (var i = 1; i < arguments.length; i++) {
82
67
  var source = arguments[i];
83
-
84
68
  for (var key in source) {
85
69
  if (Object.prototype.hasOwnProperty.call(source, key)) {
86
70
  target[key] = source[key];
87
71
  }
88
72
  }
89
73
  }
90
-
91
74
  return target;
92
75
  };
93
76
  return _extends$1.apply(this, arguments);
@@ -883,6 +866,7 @@
883
866
 
884
867
  return parsedPath;
885
868
  }
869
+
886
870
  var prefix = 'Invariant failed';
887
871
  function invariant(condition, message) {
888
872
  if (condition) {
@@ -893,11 +877,16 @@
893
877
  throw new Error(value);
894
878
  }
895
879
 
896
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
897
- // k: infer I,
898
- // ) => any
899
- // ? I
900
- // : never
880
+ /**
881
+ * router-core
882
+ *
883
+ * Copyright (c) TanStack
884
+ *
885
+ * This source code is licensed under the MIT license found in the
886
+ * LICENSE.md file in the root directory of this source tree.
887
+ *
888
+ * @license MIT
889
+ */
901
890
 
902
891
  /**
903
892
  * This function returns `a` if `b` is deeply equal.
@@ -908,89 +897,81 @@
908
897
  if (prev === next) {
909
898
  return prev;
910
899
  }
911
-
912
900
  const array = Array.isArray(prev) && Array.isArray(next);
913
-
914
901
  if (array || isPlainObject(prev) && isPlainObject(next)) {
915
902
  const aSize = array ? prev.length : Object.keys(prev).length;
916
903
  const bItems = array ? next : Object.keys(next);
917
904
  const bSize = bItems.length;
918
905
  const copy = array ? [] : {};
919
906
  let equalItems = 0;
920
-
921
907
  for (let i = 0; i < bSize; i++) {
922
908
  const key = array ? i : bItems[i];
923
909
  copy[key] = replaceEqualDeep(prev[key], next[key]);
924
-
925
910
  if (copy[key] === prev[key]) {
926
911
  equalItems++;
927
912
  }
928
913
  }
929
-
930
914
  return aSize === bSize && equalItems === aSize ? prev : copy;
931
915
  }
932
-
933
916
  return next;
934
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
917
+ }
935
918
 
919
+ // Copied from: https://github.com/jonschlinkert/is-plain-object
936
920
  function isPlainObject(o) {
937
921
  if (!hasObjectPrototype(o)) {
938
922
  return false;
939
- } // If has modified constructor
940
-
923
+ }
941
924
 
925
+ // If has modified constructor
942
926
  const ctor = o.constructor;
943
-
944
927
  if (typeof ctor === 'undefined') {
945
928
  return true;
946
- } // If has modified prototype
947
-
929
+ }
948
930
 
931
+ // If has modified prototype
949
932
  const prot = ctor.prototype;
950
-
951
933
  if (!hasObjectPrototype(prot)) {
952
934
  return false;
953
- } // If constructor does not have an Object-specific method
954
-
935
+ }
955
936
 
937
+ // If constructor does not have an Object-specific method
956
938
  if (!prot.hasOwnProperty('isPrototypeOf')) {
957
939
  return false;
958
- } // Most likely a plain Object
959
-
940
+ }
960
941
 
942
+ // Most likely a plain Object
961
943
  return true;
962
944
  }
963
-
964
945
  function hasObjectPrototype(o) {
965
946
  return Object.prototype.toString.call(o) === '[object Object]';
966
947
  }
967
-
968
948
  function last(arr) {
969
949
  return arr[arr.length - 1];
970
950
  }
971
951
  function warning(cond, message) {
972
952
  if (cond) {
973
953
  if (typeof console !== 'undefined') console.warn(message);
974
-
975
954
  try {
976
955
  throw new Error(message);
977
956
  } catch (_unused) {}
978
957
  }
979
-
980
958
  return true;
981
959
  }
982
-
983
960
  function isFunction(d) {
984
961
  return typeof d === 'function';
985
962
  }
986
-
987
963
  function functionalUpdate(updater, previous) {
988
964
  if (isFunction(updater)) {
989
965
  return updater(previous);
990
966
  }
991
-
992
967
  return updater;
993
968
  }
969
+ function pick(parent, keys) {
970
+ return keys.reduce((obj, key) => {
971
+ obj[key] = parent[key];
972
+ return obj;
973
+ }, {});
974
+ }
994
975
 
995
976
  function joinPaths(paths) {
996
977
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -1024,12 +1005,10 @@
1024
1005
  } else ;
1025
1006
  } else if (toSegment.value === '..') {
1026
1007
  var _last;
1027
-
1028
1008
  // Extra trailing slash? pop it off
1029
1009
  if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
1030
1010
  baseSegments.pop();
1031
1011
  }
1032
-
1033
1012
  baseSegments.pop();
1034
1013
  } else if (toSegment.value === '.') {
1035
1014
  return;
@@ -1044,10 +1023,8 @@
1044
1023
  if (!pathname) {
1045
1024
  return [];
1046
1025
  }
1047
-
1048
1026
  pathname = cleanPath(pathname);
1049
1027
  const segments = [];
1050
-
1051
1028
  if (pathname.slice(0, 1) === '/') {
1052
1029
  pathname = pathname.substring(1);
1053
1030
  segments.push({
@@ -1055,12 +1032,11 @@
1055
1032
  value: '/'
1056
1033
  });
1057
1034
  }
1058
-
1059
1035
  if (!pathname) {
1060
1036
  return segments;
1061
- } // Remove empty segments and '.' segments
1062
-
1037
+ }
1063
1038
 
1039
+ // Remove empty segments and '.' segments
1064
1040
  const split = pathname.split('/').filter(Boolean);
1065
1041
  segments.push(...split.map(part => {
1066
1042
  if (part.startsWith('*')) {
@@ -1069,20 +1045,17 @@
1069
1045
  value: part
1070
1046
  };
1071
1047
  }
1072
-
1073
- if (part.charAt(0) === ':') {
1048
+ if (part.charAt(0) === '$') {
1074
1049
  return {
1075
1050
  type: 'param',
1076
1051
  value: part
1077
1052
  };
1078
1053
  }
1079
-
1080
1054
  return {
1081
1055
  type: 'pathname',
1082
1056
  value: part
1083
1057
  };
1084
1058
  }));
1085
-
1086
1059
  if (pathname.slice(-1) === '/') {
1087
1060
  pathname = pathname.substring(1);
1088
1061
  segments.push({
@@ -1090,7 +1063,6 @@
1090
1063
  value: '/'
1091
1064
  });
1092
1065
  }
1093
-
1094
1066
  return segments;
1095
1067
  }
1096
1068
  function interpolatePath(path, params, leaveWildcard) {
@@ -1099,57 +1071,45 @@
1099
1071
  if (segment.value === '*' && !leaveWildcard) {
1100
1072
  return '';
1101
1073
  }
1102
-
1103
1074
  if (segment.type === 'param') {
1104
1075
  var _segment$value$substr;
1105
-
1106
1076
  return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1107
1077
  }
1108
-
1109
1078
  return segment.value;
1110
1079
  }));
1111
1080
  }
1112
1081
  function matchPathname(currentPathname, matchLocation) {
1113
- const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1082
+ const pathParams = matchByPath(currentPathname, matchLocation);
1083
+ // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1114
1084
 
1115
1085
  if (matchLocation.to && !pathParams) {
1116
1086
  return;
1117
- } // if (matchLocation.search && !searchMatched) {
1118
- // return
1119
- // }
1120
-
1121
-
1087
+ }
1122
1088
  return pathParams != null ? pathParams : {};
1123
1089
  }
1124
1090
  function matchByPath(from, matchLocation) {
1125
1091
  var _matchLocation$to;
1126
-
1127
1092
  const baseSegments = parsePathname(from);
1128
1093
  const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
1129
1094
  const params = {};
1130
-
1131
1095
  let isMatch = (() => {
1132
1096
  for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
1133
1097
  const baseSegment = baseSegments[i];
1134
1098
  const routeSegment = routeSegments[i];
1135
1099
  const isLastRouteSegment = i === routeSegments.length - 1;
1136
1100
  const isLastBaseSegment = i === baseSegments.length - 1;
1137
-
1138
1101
  if (routeSegment) {
1139
1102
  if (routeSegment.type === 'wildcard') {
1140
1103
  if (baseSegment != null && baseSegment.value) {
1141
1104
  params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
1142
1105
  return true;
1143
1106
  }
1144
-
1145
1107
  return false;
1146
1108
  }
1147
-
1148
1109
  if (routeSegment.type === 'pathname') {
1149
1110
  if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
1150
1111
  return true;
1151
1112
  }
1152
-
1153
1113
  if (baseSegment) {
1154
1114
  if (matchLocation.caseSensitive) {
1155
1115
  if (routeSegment.value !== baseSegment.value) {
@@ -1160,41 +1120,36 @@
1160
1120
  }
1161
1121
  }
1162
1122
  }
1163
-
1164
1123
  if (!baseSegment) {
1165
1124
  return false;
1166
1125
  }
1167
-
1168
1126
  if (routeSegment.type === 'param') {
1169
1127
  if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
1170
1128
  return false;
1171
1129
  }
1172
-
1173
- if (!baseSegment.value.startsWith(':')) {
1130
+ if (baseSegment.value.charAt(0) !== '$') {
1174
1131
  params[routeSegment.value.substring(1)] = baseSegment.value;
1175
1132
  }
1176
1133
  }
1177
1134
  }
1178
-
1179
1135
  if (isLastRouteSegment && !isLastBaseSegment) {
1180
1136
  return !!matchLocation.fuzzy;
1181
1137
  }
1182
1138
  }
1183
-
1184
1139
  return true;
1185
1140
  })();
1186
-
1187
1141
  return isMatch ? params : undefined;
1188
1142
  }
1189
1143
 
1190
1144
  // @ts-nocheck
1145
+
1191
1146
  // 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.
1147
+
1192
1148
  function encode(obj, pfx) {
1193
1149
  var k,
1194
- i,
1195
- tmp,
1196
- str = '';
1197
-
1150
+ i,
1151
+ tmp,
1152
+ str = '';
1198
1153
  for (k in obj) {
1199
1154
  if ((tmp = obj[k]) !== void 0) {
1200
1155
  if (Array.isArray(tmp)) {
@@ -1208,35 +1163,30 @@
1208
1163
  }
1209
1164
  }
1210
1165
  }
1211
-
1212
1166
  return (pfx || '') + str;
1213
1167
  }
1214
-
1215
1168
  function toValue(mix) {
1216
1169
  if (!mix) return '';
1217
1170
  var str = decodeURIComponent(mix);
1218
1171
  if (str === 'false') return false;
1219
1172
  if (str === 'true') return true;
1173
+ if (str.charAt(0) === '0') return str;
1220
1174
  return +str * 0 === 0 ? +str : str;
1221
1175
  }
1222
-
1223
1176
  function decode(str) {
1224
1177
  var tmp,
1225
- k,
1226
- out = {},
1227
- arr = str.split('&');
1228
-
1178
+ k,
1179
+ out = {},
1180
+ arr = str.split('&');
1229
1181
  while (tmp = arr.shift()) {
1230
1182
  tmp = tmp.split('=');
1231
1183
  k = tmp.shift();
1232
-
1233
1184
  if (out[k] !== void 0) {
1234
1185
  out[k] = [].concat(out[k], toValue(tmp.shift()));
1235
1186
  } else {
1236
1187
  out[k] = toValue(tmp.shift());
1237
1188
  }
1238
1189
  }
1239
-
1240
1190
  return out;
1241
1191
  }
1242
1192
 
@@ -1244,14 +1194,12 @@
1244
1194
  _extends = Object.assign ? Object.assign.bind() : function (target) {
1245
1195
  for (var i = 1; i < arguments.length; i++) {
1246
1196
  var source = arguments[i];
1247
-
1248
1197
  for (var key in source) {
1249
1198
  if (Object.prototype.hasOwnProperty.call(source, key)) {
1250
1199
  target[key] = source[key];
1251
1200
  }
1252
1201
  }
1253
1202
  }
1254
-
1255
1203
  return target;
1256
1204
  };
1257
1205
  return _extends.apply(this, arguments);
@@ -1264,36 +1212,31 @@
1264
1212
  path: routePath,
1265
1213
  fullPath
1266
1214
  } = routeConfig;
1267
-
1268
1215
  const action = router.state.actions[id] || (() => {
1269
1216
  router.state.actions[id] = {
1270
- pending: [],
1217
+ submissions: [],
1271
1218
  submit: async (submission, actionOpts) => {
1272
1219
  var _actionOpts$invalidat;
1273
-
1274
1220
  if (!route) {
1275
1221
  return;
1276
1222
  }
1277
-
1278
1223
  const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1224
+ if (!(actionOpts != null && actionOpts.multi)) {
1225
+ action.submissions = action.submissions.filter(d => d.isMulti);
1226
+ }
1279
1227
  const actionState = {
1280
1228
  submittedAt: Date.now(),
1281
1229
  status: 'pending',
1282
- submission
1230
+ submission,
1231
+ isMulti: !!(actionOpts != null && actionOpts.multi)
1283
1232
  };
1284
1233
  action.current = actionState;
1285
1234
  action.latest = actionState;
1286
- action.pending.push(actionState);
1287
- router.state = _extends({}, router.state, {
1288
- currentAction: actionState,
1289
- latestAction: actionState
1290
- });
1235
+ action.submissions.push(actionState);
1291
1236
  router.notify();
1292
-
1293
1237
  try {
1294
1238
  const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1295
1239
  actionState.data = res;
1296
-
1297
1240
  if (invalidate) {
1298
1241
  router.invalidateRoute({
1299
1242
  to: '.',
@@ -1301,26 +1244,20 @@
1301
1244
  });
1302
1245
  await router.reload();
1303
1246
  }
1304
-
1305
1247
  actionState.status = 'success';
1306
1248
  return res;
1307
1249
  } catch (err) {
1250
+ console.log('tanner');
1308
1251
  console.error(err);
1309
1252
  actionState.error = err;
1310
1253
  actionState.status = 'error';
1311
1254
  } finally {
1312
- action.pending = action.pending.filter(d => d !== actionState);
1313
- router.removeActionQueue.push({
1314
- action,
1315
- actionState
1316
- });
1317
1255
  router.notify();
1318
1256
  }
1319
1257
  }
1320
1258
  };
1321
1259
  return router.state.actions[id];
1322
1260
  })();
1323
-
1324
1261
  const loader = router.state.loaders[id] || (() => {
1325
1262
  router.state.loaders[id] = {
1326
1263
  pending: [],
@@ -1328,34 +1265,34 @@
1328
1265
  if (!route) {
1329
1266
  return;
1330
1267
  }
1331
-
1332
1268
  const loaderState = {
1333
1269
  loadedAt: Date.now(),
1334
1270
  loaderContext
1335
1271
  };
1336
1272
  loader.current = loaderState;
1337
1273
  loader.latest = loaderState;
1338
- loader.pending.push(loaderState); // router.state = {
1274
+ loader.pending.push(loaderState);
1275
+
1276
+ // router.state = {
1339
1277
  // ...router.state,
1340
1278
  // currentAction: loaderState,
1341
1279
  // latestAction: loaderState,
1342
1280
  // }
1343
1281
 
1344
1282
  router.notify();
1345
-
1346
1283
  try {
1347
1284
  return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
1348
1285
  } finally {
1349
- loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
1350
-
1286
+ loader.pending = loader.pending.filter(d => d !== loaderState);
1287
+ // router.removeActionQueue.push({ loader, loaderState })
1351
1288
  router.notify();
1352
1289
  }
1353
1290
  }
1354
1291
  };
1355
1292
  return router.state.loaders[id];
1356
1293
  })();
1357
-
1358
1294
  let route = {
1295
+ routeInfo: undefined,
1359
1296
  routeId: id,
1360
1297
  routeRouteId: routeId,
1361
1298
  routePath,
@@ -1388,52 +1325,37 @@
1388
1325
  });
1389
1326
  return route;
1390
1327
  }
1391
- function cascadeLoaderData(matches) {
1392
- matches.forEach((match, index) => {
1393
- const parent = matches[index - 1];
1394
-
1395
- if (parent) {
1396
- match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
1397
- }
1398
- });
1399
- }
1400
1328
 
1401
1329
  const rootRouteId = '__root__';
1402
1330
  const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
1403
1331
  if (options === void 0) {
1404
1332
  options = {};
1405
1333
  }
1406
-
1407
1334
  if (isRoot === void 0) {
1408
1335
  isRoot = true;
1409
1336
  }
1410
-
1411
1337
  if (isRoot) {
1412
1338
  options.path = rootRouteId;
1413
- } // Strip the root from parentIds
1414
-
1339
+ }
1415
1340
 
1341
+ // Strip the root from parentIds
1416
1342
  if (parentId === rootRouteId) {
1417
1343
  parentId = '';
1418
1344
  }
1345
+ let path = isRoot ? rootRouteId : options.path;
1419
1346
 
1420
- let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
1421
-
1347
+ // If the path is anything other than an index path, trim it up
1422
1348
  if (path && path !== '/') {
1423
1349
  path = trimPath(path);
1424
1350
  }
1425
-
1426
1351
  const routeId = path || options.id;
1427
1352
  let id = joinPaths([parentId, routeId]);
1428
-
1429
1353
  if (path === rootRouteId) {
1430
1354
  path = '/';
1431
1355
  }
1432
-
1433
1356
  if (id !== rootRouteId) {
1434
1357
  id = joinPaths(['/', id]);
1435
1358
  }
1436
-
1437
1359
  const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
1438
1360
  return {
1439
1361
  id: id,
@@ -1442,13 +1364,15 @@
1442
1364
  fullPath: fullPath,
1443
1365
  options: options,
1444
1366
  children,
1445
- createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
1446
1367
  addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
1447
- createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
1368
+ createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
1369
+ generate: () => {
1370
+ invariant(false, "routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. ");
1371
+ }
1448
1372
  };
1449
1373
  };
1450
1374
 
1451
- const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
1375
+ const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
1452
1376
  function createRouteMatch(router, route, opts) {
1453
1377
  const routeMatch = _extends({}, route, opts, {
1454
1378
  router,
@@ -1458,10 +1382,10 @@
1458
1382
  status: 'idle',
1459
1383
  routeLoaderData: {},
1460
1384
  loaderData: {},
1461
- isPending: false,
1462
1385
  isFetching: false,
1463
1386
  isInvalid: false,
1464
1387
  invalidAt: Infinity,
1388
+ // pendingActions: [],
1465
1389
  getIsInvalid: () => {
1466
1390
  const now = Date.now();
1467
1391
  return routeMatch.isInvalid || routeMatch.invalidAt < now;
@@ -1472,63 +1396,30 @@
1472
1396
  resolve: () => {},
1473
1397
  notify: () => {
1474
1398
  routeMatch.__.resolve();
1475
-
1476
1399
  routeMatch.router.notify();
1477
1400
  },
1478
- startPending: () => {
1479
- var _routeMatch$options$p, _routeMatch$options$p2;
1480
-
1481
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
1482
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
1483
-
1484
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
1485
- return;
1486
- }
1487
-
1488
- routeMatch.__.pendingTimeout = setTimeout(() => {
1489
- routeMatch.isPending = true;
1490
-
1491
- routeMatch.__.resolve();
1492
-
1493
- if (typeof pendingMinMs !== 'undefined') {
1494
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
1495
- }
1496
- }, pendingMs);
1497
- },
1498
- cancelPending: () => {
1499
- routeMatch.isPending = false;
1500
- clearTimeout(routeMatch.__.pendingTimeout);
1501
- clearTimeout(routeMatch.__.pendingMinTimeout);
1502
- delete routeMatch.__.pendingMinPromise;
1503
- },
1504
- // setParentMatch: (parentMatch?: RouteMatch) => {
1505
- // routeMatch.parentMatch = parentMatch
1506
- // },
1507
- // addChildMatch: (childMatch: RouteMatch) => {
1508
- // if (
1509
- // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1510
- // ) {
1511
- // return
1512
- // }
1513
- // routeMatch.childMatches.push(childMatch)
1514
- // },
1515
1401
  validate: () => {
1516
1402
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1517
-
1518
1403
  // Validate the search params and stabilize them
1519
1404
  const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1520
-
1521
1405
  try {
1406
+ var _validator;
1522
1407
  const prevSearch = routeMatch.routeSearch;
1523
1408
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1524
- let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
1409
+ let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
1525
1410
 
1411
+ // Invalidate route matches when search param stability changes
1526
1412
  if (prevSearch !== nextSearch) {
1527
1413
  routeMatch.isInvalid = true;
1528
1414
  }
1529
-
1530
1415
  routeMatch.routeSearch = nextSearch;
1531
1416
  routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1417
+ componentTypes.map(async type => {
1418
+ const component = routeMatch.options[type];
1419
+ if (typeof routeMatch.__[type] !== 'function') {
1420
+ routeMatch.__[type] = component;
1421
+ }
1422
+ });
1532
1423
  } catch (err) {
1533
1424
  console.error(err);
1534
1425
  const error = new Error('Invalid search params found', {
@@ -1536,162 +1427,129 @@
1536
1427
  });
1537
1428
  error.code = 'INVALID_SEARCH_PARAMS';
1538
1429
  routeMatch.status = 'error';
1539
- routeMatch.error = error; // Do not proceed with loading the route
1540
-
1430
+ routeMatch.error = error;
1431
+ // Do not proceed with loading the route
1541
1432
  return;
1542
1433
  }
1543
1434
  }
1544
1435
  },
1545
1436
  cancel: () => {
1546
1437
  var _routeMatch$__$abortC;
1547
-
1548
1438
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1549
-
1550
- routeMatch.__.cancelPending();
1551
1439
  },
1552
1440
  invalidate: () => {
1553
1441
  routeMatch.isInvalid = true;
1554
1442
  },
1555
1443
  hasLoaders: () => {
1556
- return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
1444
+ return !!(route.options.loader || componentTypes.some(d => {
1445
+ var _route$options$d;
1446
+ return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
1447
+ }));
1557
1448
  },
1558
1449
  load: async loaderOpts => {
1559
1450
  const now = Date.now();
1560
- const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0; // If this is a preload, add it to the preload cache
1451
+ const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
1561
1452
 
1453
+ // If this is a preload, add it to the preload cache
1562
1454
  if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
1563
1455
  // If the match is currently active, don't preload it
1564
1456
  if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
1565
1457
  return;
1566
1458
  }
1567
-
1568
1459
  router.matchCache[routeMatch.matchId] = {
1569
1460
  gc: now + loaderOpts.gcMaxAge,
1570
1461
  match: routeMatch
1571
1462
  };
1572
- } // If the match is invalid, errored or idle, trigger it to load
1573
-
1463
+ }
1574
1464
 
1465
+ // If the match is invalid, errored or idle, trigger it to load
1575
1466
  if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1576
1467
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1577
- routeMatch.fetch({
1468
+ await routeMatch.fetch({
1578
1469
  maxAge
1579
1470
  });
1580
1471
  }
1581
1472
  },
1582
1473
  fetch: async opts => {
1583
- const id = '' + Date.now() + Math.random();
1584
- routeMatch.__.latestId = id; // If the match was in an error state, set it
1474
+ const loadId = '' + Date.now() + Math.random();
1475
+ routeMatch.__.latestId = loadId;
1476
+ const checkLatest = async () => {
1477
+ if (loadId !== routeMatch.__.latestId) {
1478
+ // warning(true, 'Data loader is out of date!')
1479
+ return new Promise(() => {});
1480
+ }
1481
+ };
1482
+
1483
+ // If the match was in an error state, set it
1585
1484
  // to a loading state again. Otherwise, keep it
1586
1485
  // as loading or resolved
1587
-
1588
1486
  if (routeMatch.status === 'idle') {
1589
1487
  routeMatch.status = 'loading';
1590
- } // We started loading the route, so it's no longer invalid
1591
-
1488
+ }
1592
1489
 
1490
+ // We started loading the route, so it's no longer invalid
1593
1491
  routeMatch.isInvalid = false;
1594
1492
  routeMatch.__.loadPromise = new Promise(async resolve => {
1595
1493
  // We are now fetching, even if it's in the background of a
1596
1494
  // resolved state
1597
1495
  routeMatch.isFetching = true;
1598
1496
  routeMatch.__.resolve = resolve;
1599
-
1600
- const loaderPromise = (async () => {
1601
- // Load the elements and data in parallel
1602
- routeMatch.__.elementsPromise = (async () => {
1603
- // then run all element and data loaders in parallel
1604
- // For each element type, potentially load it asynchronously
1605
- await Promise.all(elementTypes.map(async type => {
1606
- const routeElement = routeMatch.options[type];
1607
-
1608
- if (routeMatch.__[type]) {
1609
- return;
1610
- }
1611
-
1612
- routeMatch.__[type] = await router.options.createElement(routeElement);
1613
- }));
1614
- })();
1615
-
1616
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1617
- try {
1618
- var _ref, _ref2, _opts$maxAge;
1619
-
1620
- if (routeMatch.options.loader) {
1621
- const data = await routeMatch.options.loader({
1622
- params: routeMatch.params,
1623
- search: routeMatch.routeSearch,
1624
- signal: routeMatch.__.abortController.signal
1625
- });
1626
-
1627
- if (id !== routeMatch.__.latestId) {
1628
- return routeMatch.__.loaderPromise;
1629
- }
1630
-
1631
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1632
- }
1633
-
1634
- routeMatch.error = undefined;
1635
- routeMatch.status = 'success';
1636
- routeMatch.updatedAt = Date.now();
1637
- 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);
1638
- } catch (err) {
1639
- if (id !== routeMatch.__.latestId) {
1640
- return routeMatch.__.loaderPromise;
1641
- }
1642
-
1643
- {
1644
- console.error(err);
1645
- }
1646
-
1647
- routeMatch.error = err;
1648
- routeMatch.status = 'error';
1649
- routeMatch.updatedAt = Date.now();
1497
+ routeMatch.__.componentsPromise = (async () => {
1498
+ // then run all component and data loaders in parallel
1499
+ // For each component type, potentially load it asynchronously
1500
+
1501
+ await Promise.all(componentTypes.map(async type => {
1502
+ var _routeMatch$__$type;
1503
+ const component = routeMatch.options[type];
1504
+ if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
1505
+ routeMatch.__[type] = await router.options.loadComponent(component);
1650
1506
  }
1651
- });
1652
-
1507
+ }));
1508
+ })();
1509
+ routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1653
1510
  try {
1654
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1655
-
1656
- if (id !== routeMatch.__.latestId) {
1657
- return routeMatch.__.loaderPromise;
1658
- }
1659
-
1660
- if (routeMatch.__.pendingMinPromise) {
1661
- await routeMatch.__.pendingMinPromise;
1662
- delete routeMatch.__.pendingMinPromise;
1511
+ var _ref, _ref2, _opts$maxAge;
1512
+ if (routeMatch.options.loader) {
1513
+ const data = await router.loadMatchData(routeMatch);
1514
+ await checkLatest();
1515
+ routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1663
1516
  }
1664
- } finally {
1665
- if (id !== routeMatch.__.latestId) {
1666
- return routeMatch.__.loaderPromise;
1517
+ routeMatch.error = undefined;
1518
+ routeMatch.status = 'success';
1519
+ routeMatch.updatedAt = Date.now();
1520
+ 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);
1521
+ return routeMatch.routeLoaderData;
1522
+ } catch (err) {
1523
+ await checkLatest();
1524
+ {
1525
+ console.error(err);
1667
1526
  }
1668
-
1669
- routeMatch.__.cancelPending();
1670
-
1671
- routeMatch.isPending = false;
1672
- routeMatch.isFetching = false;
1673
-
1674
- routeMatch.__.notify();
1527
+ routeMatch.error = err;
1528
+ routeMatch.status = 'error';
1529
+ routeMatch.updatedAt = Date.now();
1530
+ throw err;
1675
1531
  }
1676
- })();
1677
-
1678
- routeMatch.__.loaderPromise = loaderPromise;
1679
- await loaderPromise;
1680
-
1681
- if (id !== routeMatch.__.latestId) {
1682
- return routeMatch.__.loaderPromise;
1532
+ });
1533
+ const after = async () => {
1534
+ await checkLatest();
1535
+ routeMatch.isFetching = false;
1536
+ delete routeMatch.__.loadPromise;
1537
+ routeMatch.__.notify();
1538
+ };
1539
+ try {
1540
+ await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
1541
+ after();
1542
+ } catch (_unused) {
1543
+ after();
1683
1544
  }
1684
-
1685
- delete routeMatch.__.loaderPromise;
1686
1545
  });
1687
- return await routeMatch.__.loadPromise;
1546
+ await routeMatch.__.loadPromise;
1547
+ await checkLatest();
1688
1548
  }
1689
1549
  });
1690
-
1691
1550
  if (!routeMatch.hasLoaders()) {
1692
1551
  routeMatch.status = 'success';
1693
1552
  }
1694
-
1695
1553
  return routeMatch;
1696
1554
  }
1697
1555
 
@@ -1702,42 +1560,39 @@
1702
1560
  if (searchStr.substring(0, 1) === '?') {
1703
1561
  searchStr = searchStr.substring(1);
1704
1562
  }
1563
+ let query = decode(searchStr);
1705
1564
 
1706
- let query = decode(searchStr); // Try to parse any query params that might be json
1707
-
1565
+ // Try to parse any query params that might be json
1708
1566
  for (let key in query) {
1709
1567
  const value = query[key];
1710
-
1711
1568
  if (typeof value === 'string') {
1712
1569
  try {
1713
1570
  query[key] = parser(value);
1714
- } catch (err) {//
1571
+ } catch (err) {
1572
+ //
1715
1573
  }
1716
1574
  }
1717
1575
  }
1718
-
1719
1576
  return query;
1720
1577
  };
1721
1578
  }
1722
1579
  function stringifySearchWith(stringify) {
1723
1580
  return search => {
1724
1581
  search = _extends({}, search);
1725
-
1726
1582
  if (search) {
1727
1583
  Object.keys(search).forEach(key => {
1728
1584
  const val = search[key];
1729
-
1730
1585
  if (typeof val === 'undefined' || val === undefined) {
1731
1586
  delete search[key];
1732
1587
  } else if (val && typeof val === 'object' && val !== null) {
1733
1588
  try {
1734
1589
  search[key] = stringify(val);
1735
- } catch (err) {// silent
1590
+ } catch (err) {
1591
+ // silent
1736
1592
  }
1737
1593
  }
1738
1594
  });
1739
1595
  }
1740
-
1741
1596
  const searchStr = encode(search).toString();
1742
1597
  return searchStr ? "?" + searchStr : '';
1743
1598
  };
@@ -1745,50 +1600,53 @@
1745
1600
 
1746
1601
  var _window$document;
1747
1602
  // Detect if we're in the DOM
1748
- const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
1603
+ const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
1749
1604
 
1605
+ // This is the default history object if none is defined
1750
1606
  const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
1751
-
1607
+ function getInitialRouterState() {
1608
+ return {
1609
+ status: 'idle',
1610
+ location: null,
1611
+ matches: [],
1612
+ actions: {},
1613
+ loaders: {},
1614
+ lastUpdated: Date.now(),
1615
+ isFetching: false,
1616
+ isPreloading: false
1617
+ };
1618
+ }
1752
1619
  function createRouter(userOptions) {
1753
1620
  var _userOptions$stringif, _userOptions$parseSea;
1754
-
1755
1621
  const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
1756
-
1757
1622
  const originalOptions = _extends({
1758
1623
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
1759
1624
  defaultLoaderMaxAge: 0,
1760
1625
  defaultPreloadMaxAge: 2000,
1761
- defaultPreloadDelay: 50
1626
+ defaultPreloadDelay: 50,
1627
+ context: undefined
1762
1628
  }, userOptions, {
1763
1629
  stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1764
1630
  parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
1765
1631
  });
1766
-
1767
1632
  let router = {
1633
+ types: undefined,
1634
+ // public api
1768
1635
  history,
1769
1636
  options: originalOptions,
1770
1637
  listeners: [],
1771
- removeActionQueue: [],
1772
1638
  // Resolved after construction
1773
1639
  basepath: '',
1774
1640
  routeTree: undefined,
1775
1641
  routesById: {},
1776
1642
  location: undefined,
1777
- allRouteInfo: undefined,
1778
1643
  //
1779
- navigationPromise: Promise.resolve(),
1780
1644
  resolveNavigation: () => {},
1781
1645
  matchCache: {},
1782
- state: {
1783
- status: 'idle',
1784
- location: null,
1785
- matches: [],
1786
- actions: {},
1787
- loaders: {},
1788
- loaderData: {},
1789
- lastUpdated: Date.now(),
1790
- isFetching: false,
1791
- isPreloading: false
1646
+ state: getInitialRouterState(),
1647
+ reset: () => {
1648
+ router.state = getInitialRouterState();
1649
+ router.notify();
1792
1650
  },
1793
1651
  startedLoadingAt: Date.now(),
1794
1652
  subscribe: listener => {
@@ -1801,62 +1659,104 @@
1801
1659
  return router.routesById[id];
1802
1660
  },
1803
1661
  notify: () => {
1804
- router.state = _extends({}, router.state, {
1805
- isFetching: router.state.status === 'loading' || router.state.matches.some(d => d.isFetching),
1806
- isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
1807
- });
1662
+ const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
1663
+ const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
1664
+ if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
1665
+ router.state = _extends({}, router.state, {
1666
+ isFetching,
1667
+ isPreloading
1668
+ });
1669
+ }
1808
1670
  cascadeLoaderData(router.state.matches);
1809
1671
  router.listeners.forEach(listener => listener(router));
1810
1672
  },
1673
+ dehydrate: () => {
1674
+ return {
1675
+ location: router.location,
1676
+ state: _extends({}, pick(router.state, ['status', 'location', 'lastUpdated', 'location']), {
1677
+ matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1678
+ }),
1679
+ context: router.options.context
1680
+ };
1681
+ },
1682
+ hydrate: dehydratedState => {
1683
+ // Update the location
1684
+ router.location = dehydratedState.location;
1685
+
1686
+ // Update the context
1687
+ router.options.context = dehydratedState.context;
1688
+
1689
+ // Match the routes
1690
+ const matches = router.matchRoutes(router.location.pathname, {
1691
+ strictParseParams: true
1692
+ });
1693
+ matches.forEach((match, index) => {
1694
+ const dehydratedMatch = dehydratedState.state.matches[index];
1695
+ invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1696
+ Object.assign(match, dehydratedMatch);
1697
+ });
1698
+ matches.forEach(match => match.__.validate());
1699
+ router.state = _extends({}, router.state, dehydratedState, {
1700
+ matches
1701
+ });
1702
+ },
1811
1703
  mount: () => {
1812
1704
  const next = router.__.buildLocation({
1813
1705
  to: '.',
1814
1706
  search: true,
1815
1707
  hash: true
1816
- }); // If the current location isn't updated, trigger a navigation
1817
- // to the current location. Otherwise, load the current location.
1818
-
1708
+ });
1819
1709
 
1710
+ // If the current location isn't updated, trigger a navigation
1711
+ // to the current location. Otherwise, load the current location.
1820
1712
  if (next.href !== router.location.href) {
1821
1713
  router.__.commitLocation(next, true);
1822
- } else {
1823
- router.loadLocation();
1824
1714
  }
1715
+ if (!router.state.matches.length) {
1716
+ router.load();
1717
+ }
1718
+ const unsub = router.history.listen(event => {
1719
+ router.load(router.__.parseLocation(event.location, router.location));
1720
+ });
1825
1721
 
1826
- const unsub = history.listen(event => {
1827
- router.loadLocation(router.__.parseLocation(event.location, router.location));
1828
- }); // addEventListener does not exist in React Native, but window does
1722
+ // addEventListener does not exist in React Native, but window does
1829
1723
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1830
-
1831
1724
  if (!isServer && window.addEventListener) {
1832
1725
  // Listen to visibillitychange and focus
1833
1726
  window.addEventListener('visibilitychange', router.onFocus, false);
1834
1727
  window.addEventListener('focus', router.onFocus, false);
1835
1728
  }
1836
-
1837
1729
  return () => {
1838
- unsub(); // Be sure to unsubscribe if a new handler is set
1839
-
1840
- window.removeEventListener('visibilitychange', router.onFocus);
1841
- window.removeEventListener('focus', router.onFocus);
1730
+ unsub();
1731
+ if (!isServer && window.removeEventListener) {
1732
+ // Be sure to unsubscribe if a new handler is set
1733
+ window.removeEventListener('visibilitychange', router.onFocus);
1734
+ window.removeEventListener('focus', router.onFocus);
1735
+ }
1842
1736
  };
1843
1737
  },
1844
1738
  onFocus: () => {
1845
- router.loadLocation();
1739
+ router.load();
1846
1740
  },
1847
1741
  update: opts => {
1742
+ const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1743
+ if (!router.location || newHistory) {
1744
+ if (opts != null && opts.history) {
1745
+ router.history = opts.history;
1746
+ }
1747
+ router.location = router.__.parseLocation(router.history.location);
1748
+ router.state.location = router.location;
1749
+ }
1848
1750
  Object.assign(router.options, opts);
1849
1751
  const {
1850
1752
  basepath,
1851
1753
  routeConfig
1852
1754
  } = router.options;
1853
1755
  router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
1854
-
1855
1756
  if (routeConfig) {
1856
1757
  router.routesById = {};
1857
1758
  router.routeTree = router.__.buildRouteTree(routeConfig);
1858
1759
  }
1859
-
1860
1760
  return router;
1861
1761
  },
1862
1762
  cancelMatches: () => {
@@ -1865,58 +1765,60 @@
1865
1765
  match.cancel();
1866
1766
  });
1867
1767
  },
1868
- loadLocation: async next => {
1768
+ load: async next => {
1869
1769
  const id = Math.random();
1870
1770
  router.startedLoadingAt = id;
1871
-
1872
1771
  if (next) {
1873
1772
  // Ingest the new location
1874
1773
  router.location = next;
1875
- } // Clear out old actions
1876
-
1877
-
1878
- router.removeActionQueue.forEach(_ref => {
1879
- let {
1880
- action,
1881
- actionState
1882
- } = _ref;
1883
-
1884
- if (router.state.currentAction === actionState) {
1885
- router.state.currentAction = undefined;
1886
- }
1887
-
1888
- if (action.current === actionState) {
1889
- action.current = undefined;
1890
- }
1891
- });
1892
- router.removeActionQueue = []; // Cancel any pending matches
1774
+ }
1893
1775
 
1894
- router.cancelMatches(); // Match the routes
1776
+ // Cancel any pending matches
1777
+ router.cancelMatches();
1895
1778
 
1896
- const matches = router.matchRoutes(location.pathname, {
1779
+ // Match the routes
1780
+ const matches = router.matchRoutes(router.location.pathname, {
1897
1781
  strictParseParams: true
1898
1782
  });
1899
- router.state = _extends({}, router.state, {
1900
- pending: {
1783
+ if (typeof document !== 'undefined') {
1784
+ router.state = _extends({}, router.state, {
1785
+ pending: {
1786
+ matches: matches,
1787
+ location: router.location
1788
+ },
1789
+ status: 'loading'
1790
+ });
1791
+ } else {
1792
+ router.state = _extends({}, router.state, {
1901
1793
  matches: matches,
1902
- location: router.location
1903
- },
1904
- status: 'loading'
1905
- });
1906
- router.notify(); // Load the matches
1794
+ location: router.location,
1795
+ status: 'loading'
1796
+ });
1797
+ }
1907
1798
 
1908
- await router.loadMatches(matches, {
1909
- withPending: true
1910
- });
1799
+ // Check if each match middleware to see if the route can be accessed
1800
+ try {
1801
+ await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1802
+ router: router,
1803
+ match
1804
+ })));
1805
+ } catch (err) {
1806
+ if (err != null && err.then) {
1807
+ await new Promise(() => {});
1808
+ }
1809
+ throw err;
1810
+ }
1811
+ router.notify();
1911
1812
 
1813
+ // Load the matches
1814
+ await router.loadMatches(matches);
1912
1815
  if (router.startedLoadingAt !== id) {
1913
1816
  // Ignore side-effects of match loading
1914
1817
  return router.navigationPromise;
1915
1818
  }
1916
-
1917
1819
  const previousMatches = router.state.matches;
1918
1820
  const exiting = [],
1919
- staying = [];
1821
+ staying = [];
1920
1822
  previousMatches.forEach(d => {
1921
1823
  if (matches.find(dd => dd.matchId === d.matchId)) {
1922
1824
  staying.push(d);
@@ -1924,22 +1826,23 @@
1924
1826
  exiting.push(d);
1925
1827
  }
1926
1828
  });
1829
+ const entering = matches.filter(d => {
1830
+ return !previousMatches.find(dd => dd.matchId === d.matchId);
1831
+ });
1927
1832
  const now = Date.now();
1928
1833
  exiting.forEach(d => {
1929
- var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
1930
-
1834
+ var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
1931
1835
  d.__.onExit == null ? void 0 : d.__.onExit({
1932
1836
  params: d.params,
1933
1837
  search: d.routeSearch
1934
- }); // Clear idle error states when match leaves
1838
+ });
1935
1839
 
1840
+ // Clear idle error states when match leaves
1936
1841
  if (d.status === 'error' && !d.isFetching) {
1937
1842
  d.status = 'idle';
1938
1843
  d.error = undefined;
1939
1844
  }
1940
-
1941
- 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);
1942
-
1845
+ 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);
1943
1846
  if (gc > 0) {
1944
1847
  router.matchCache[d.matchId] = {
1945
1848
  gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
@@ -1953,27 +1856,24 @@
1953
1856
  search: d.routeSearch
1954
1857
  });
1955
1858
  });
1956
- const entering = matches.filter(d => {
1957
- return !previousMatches.find(dd => dd.matchId === d.matchId);
1958
- });
1959
1859
  entering.forEach(d => {
1960
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
1860
+ d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1961
1861
  params: d.params,
1962
1862
  search: d.search
1963
1863
  });
1964
1864
  delete router.matchCache[d.matchId];
1965
1865
  });
1966
-
1967
- if (matches.some(d => d.status === 'loading')) {
1968
- router.notify();
1969
- await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
1970
- }
1971
-
1972
1866
  if (router.startedLoadingAt !== id) {
1973
1867
  // Ignore side-effects of match loading
1974
1868
  return;
1975
1869
  }
1976
-
1870
+ matches.forEach(match => {
1871
+ // Clear actions
1872
+ if (match.action) {
1873
+ match.action.current = undefined;
1874
+ match.action.submissions = [];
1875
+ }
1876
+ });
1977
1877
  router.state = _extends({}, router.state, {
1978
1878
  location: router.location,
1979
1879
  matches,
@@ -1986,18 +1886,19 @@
1986
1886
  cleanMatchCache: () => {
1987
1887
  const now = Date.now();
1988
1888
  Object.keys(router.matchCache).forEach(matchId => {
1989
- const entry = router.matchCache[matchId]; // Don't remove loading matches
1889
+ const entry = router.matchCache[matchId];
1990
1890
 
1891
+ // Don't remove loading matches
1991
1892
  if (entry.match.status === 'loading') {
1992
1893
  return;
1993
- } // Do not remove successful matches that are still valid
1994
-
1894
+ }
1995
1895
 
1896
+ // Do not remove successful matches that are still valid
1996
1897
  if (entry.gc > 0 && entry.gc > now) {
1997
1898
  return;
1998
- } // Everything else gets removed
1999
-
1899
+ }
2000
1900
 
1901
+ // Everything else gets removed
2001
1902
  delete router.matchCache[matchId];
2002
1903
  });
2003
1904
  },
@@ -2005,7 +1906,6 @@
2005
1906
  if (navigateOpts === void 0) {
2006
1907
  navigateOpts = router.location;
2007
1908
  }
2008
-
2009
1909
  const next = router.buildNext(navigateOpts);
2010
1910
  const matches = router.matchRoutes(next.pathname, {
2011
1911
  strictParseParams: true
@@ -2014,108 +1914,87 @@
2014
1914
  return matches;
2015
1915
  },
2016
1916
  preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
2017
- var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
2018
-
1917
+ var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
2019
1918
  if (navigateOpts === void 0) {
2020
1919
  navigateOpts = router.location;
2021
1920
  }
2022
-
2023
1921
  const next = router.buildNext(navigateOpts);
2024
1922
  const matches = router.matchRoutes(next.pathname, {
2025
1923
  strictParseParams: true
2026
1924
  });
2027
1925
  await router.loadMatches(matches, {
2028
1926
  preload: true,
2029
- maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
2030
- gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
1927
+ maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
1928
+ gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
2031
1929
  });
2032
1930
  return matches;
2033
1931
  },
2034
1932
  matchRoutes: (pathname, opts) => {
2035
1933
  var _router$state$pending3, _router$state$pending4;
2036
-
2037
1934
  router.cleanMatchCache();
2038
1935
  const matches = [];
2039
-
2040
1936
  if (!router.routeTree) {
2041
1937
  return matches;
2042
1938
  }
2043
-
2044
1939
  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 : [])];
2045
-
2046
1940
  const recurse = async routes => {
2047
1941
  var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
2048
-
2049
1942
  const parentMatch = last(matches);
2050
1943
  let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
2051
1944
  const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
2052
1945
  let foundRoutes = [];
2053
-
2054
1946
  const findMatchInRoutes = (parentRoutes, routes) => {
2055
1947
  routes.some(route => {
2056
1948
  var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
2057
-
2058
1949
  if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
2059
1950
  return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
2060
1951
  }
2061
-
2062
1952
  const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
2063
1953
  const matchParams = matchPathname(pathname, {
2064
1954
  to: route.fullPath,
2065
1955
  fuzzy,
2066
1956
  caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
2067
1957
  });
2068
-
2069
1958
  if (matchParams) {
2070
1959
  let parsedParams;
2071
-
2072
1960
  try {
2073
1961
  var _route$options$parseP;
2074
-
2075
1962
  parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
2076
1963
  } catch (err) {
2077
1964
  if (opts != null && opts.strictParseParams) {
2078
1965
  throw err;
2079
1966
  }
2080
1967
  }
2081
-
2082
1968
  params = _extends({}, params, parsedParams);
2083
1969
  }
2084
-
2085
1970
  if (!!matchParams) {
2086
1971
  foundRoutes = [...parentRoutes, route];
2087
1972
  }
2088
-
2089
1973
  return !!foundRoutes.length;
2090
1974
  });
2091
1975
  return !!foundRoutes.length;
2092
1976
  };
2093
-
2094
1977
  findMatchInRoutes([], filteredRoutes);
2095
-
2096
1978
  if (!foundRoutes.length) {
2097
1979
  return;
2098
1980
  }
2099
-
2100
1981
  foundRoutes.forEach(foundRoute => {
2101
1982
  var _router$matchCache$ma;
2102
-
2103
1983
  const interpolatedPath = interpolatePath(foundRoute.routePath, params);
2104
1984
  const matchId = interpolatePath(foundRoute.routeId, params, true);
2105
1985
  const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
1986
+ parentMatch,
2106
1987
  matchId,
2107
1988
  params,
2108
- pathname: joinPaths([pathname, interpolatedPath])
1989
+ pathname: joinPaths([router.basepath, interpolatedPath])
2109
1990
  });
2110
1991
  matches.push(match);
2111
1992
  });
2112
1993
  const foundRoute = last(foundRoutes);
2113
-
2114
1994
  if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
2115
1995
  recurse(foundRoute.childRoutes);
2116
1996
  }
2117
1997
  };
2118
-
2119
1998
  recurse([router.routeTree]);
2120
1999
  cascadeLoaderData(matches);
2121
2000
  return matches;
@@ -2124,23 +2003,61 @@
2124
2003
  const matchPromises = resolvedMatches.map(async match => {
2125
2004
  // Validate the match (loads search params etc)
2126
2005
  match.__.validate();
2127
-
2128
2006
  match.load(loaderOpts);
2129
-
2130
- if (match.status === 'loading') {
2131
- // If requested, start the pending timers
2132
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
2133
- // This might be completion, error, or a pending state
2134
-
2007
+ const search = match.search;
2008
+ if (search.__data && search.__data.matchId !== match.matchId) {
2009
+ return;
2010
+ }
2011
+ if (match.__.loadPromise) {
2012
+ // Wait for the first sign of activity from the match
2135
2013
  await match.__.loadPromise;
2136
2014
  }
2137
2015
  });
2138
2016
  router.notify();
2139
2017
  await Promise.all(matchPromises);
2140
2018
  },
2019
+ loadMatchData: async routeMatch => {
2020
+ if (isServer || !router.options.useServerData) {
2021
+ var _await$routeMatch$opt;
2022
+ return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2023
+ // parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
2024
+ params: routeMatch.params,
2025
+ search: routeMatch.routeSearch,
2026
+ signal: routeMatch.__.abortController.signal
2027
+ }))) != null ? _await$routeMatch$opt : {};
2028
+ } else {
2029
+ const next = router.buildNext({
2030
+ to: '.',
2031
+ search: d => _extends({}, d != null ? d : {}, {
2032
+ __data: {
2033
+ matchId: routeMatch.matchId
2034
+ }
2035
+ })
2036
+ });
2037
+
2038
+ // Refresh:
2039
+ // '/dashboard'
2040
+ // '/dashboard/invoices/'
2041
+ // '/dashboard/invoices/123'
2042
+
2043
+ // New:
2044
+ // '/dashboard/invoices/456'
2045
+
2046
+ // TODO: batch requests when possible
2047
+
2048
+ const res = await fetch(next.href, {
2049
+ method: 'GET'
2050
+ // signal: routeMatch.__.abortController.signal,
2051
+ });
2052
+
2053
+ if (res.ok) {
2054
+ return res.json();
2055
+ }
2056
+ throw new Error('Failed to fetch match data');
2057
+ }
2058
+ },
2141
2059
  invalidateRoute: opts => {
2142
2060
  var _router$state$pending5, _router$state$pending6;
2143
-
2144
2061
  const next = router.buildNext(opts);
2145
2062
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
2146
2063
  [...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 => {
@@ -2159,30 +2076,26 @@
2159
2076
  },
2160
2077
  matchRoute: (location, opts) => {
2161
2078
  var _location$from;
2162
-
2163
2079
  // const location = router.buildNext(opts)
2080
+
2164
2081
  location = _extends({}, location, {
2165
2082
  to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
2166
2083
  });
2167
2084
  const next = router.buildNext(location);
2168
-
2169
2085
  if (opts != null && opts.pending) {
2170
2086
  var _router$state$pending7;
2171
-
2172
2087
  if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
2173
2088
  return false;
2174
2089
  }
2175
-
2176
2090
  return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
2177
2091
  to: next.pathname
2178
2092
  }));
2179
2093
  }
2180
-
2181
2094
  return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
2182
2095
  to: next.pathname
2183
2096
  }));
2184
2097
  },
2185
- navigate: async _ref8 => {
2098
+ navigate: async _ref7 => {
2186
2099
  let {
2187
2100
  from,
2188
2101
  to = '.',
@@ -2190,20 +2103,19 @@
2190
2103
  hash,
2191
2104
  replace,
2192
2105
  params
2193
- } = _ref8;
2106
+ } = _ref7;
2194
2107
  // If this link simply reloads the current route,
2195
2108
  // make sure it has a new key so it will trigger a data refresh
2109
+
2196
2110
  // If this `to` is a valid external URL, return
2197
2111
  // null for LinkUtils
2198
2112
  const toString = String(to);
2199
2113
  const fromString = String(from);
2200
2114
  let isExternal;
2201
-
2202
2115
  try {
2203
2116
  new URL("" + toString);
2204
2117
  isExternal = true;
2205
2118
  } catch (e) {}
2206
-
2207
2119
  invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
2208
2120
  return router.__.navigate({
2209
2121
  from: fromString,
@@ -2214,9 +2126,8 @@
2214
2126
  params
2215
2127
  });
2216
2128
  },
2217
- buildLink: _ref9 => {
2218
- var _preload, _ref10;
2219
-
2129
+ buildLink: _ref8 => {
2130
+ var _preload, _ref9;
2220
2131
  let {
2221
2132
  from,
2222
2133
  to = '.',
@@ -2231,12 +2142,13 @@
2231
2142
  preloadGcMaxAge: userPreloadGcMaxAge,
2232
2143
  preloadDelay: userPreloadDelay,
2233
2144
  disabled
2234
- } = _ref9;
2235
-
2145
+ } = _ref8;
2236
2146
  // If this link simply reloads the current route,
2237
2147
  // make sure it has a new key so it will trigger a data refresh
2148
+
2238
2149
  // If this `to` is a valid external URL, return
2239
2150
  // null for LinkUtils
2151
+
2240
2152
  try {
2241
2153
  new URL("" + to);
2242
2154
  return {
@@ -2244,7 +2156,6 @@
2244
2156
  href: to
2245
2157
  };
2246
2158
  } catch (e) {}
2247
-
2248
2159
  const nextOpts = {
2249
2160
  from,
2250
2161
  to,
@@ -2255,33 +2166,35 @@
2255
2166
  };
2256
2167
  const next = router.buildNext(nextOpts);
2257
2168
  preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2258
- const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
2169
+ const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
2259
2170
 
2171
+ // Compare path/hash for matches
2260
2172
  const pathIsEqual = router.state.location.pathname === next.pathname;
2261
2173
  const currentPathSplit = router.state.location.pathname.split('/');
2262
2174
  const nextPathSplit = next.pathname.split('/');
2263
2175
  const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
2264
- const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
2265
-
2176
+ const hashIsEqual = router.state.location.hash === next.hash;
2177
+ // Combine the matches based on user options
2266
2178
  const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
2267
- const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
2179
+ const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
2268
2180
 
2269
- const isActive = pathTest && hashTest; // The click handler
2181
+ // The final "active" test
2182
+ const isActive = pathTest && hashTest;
2270
2183
 
2184
+ // The click handler
2271
2185
  const handleClick = e => {
2272
2186
  if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
2273
2187
  e.preventDefault();
2274
-
2275
2188
  if (pathIsEqual && !search && !hash) {
2276
2189
  router.invalidateRoute(nextOpts);
2277
- } // All is well? Navigate!)
2278
-
2190
+ }
2279
2191
 
2192
+ // All is well? Navigate!)
2280
2193
  router.__.navigate(nextOpts);
2281
2194
  }
2282
- }; // The click handler
2283
-
2195
+ };
2284
2196
 
2197
+ // The click handler
2285
2198
  const handleFocus = e => {
2286
2199
  if (preload) {
2287
2200
  router.preloadRoute(nextOpts, {
@@ -2290,15 +2203,12 @@
2290
2203
  });
2291
2204
  }
2292
2205
  };
2293
-
2294
2206
  const handleEnter = e => {
2295
2207
  const target = e.target || {};
2296
-
2297
2208
  if (preload) {
2298
2209
  if (target.preloadTimeout) {
2299
2210
  return;
2300
2211
  }
2301
-
2302
2212
  target.preloadTimeout = setTimeout(() => {
2303
2213
  target.preloadTimeout = null;
2304
2214
  router.preloadRoute(nextOpts, {
@@ -2308,16 +2218,13 @@
2308
2218
  }, preloadDelay);
2309
2219
  }
2310
2220
  };
2311
-
2312
2221
  const handleLeave = e => {
2313
2222
  const target = e.target || {};
2314
-
2315
2223
  if (target.preloadTimeout) {
2316
2224
  clearTimeout(target.preloadTimeout);
2317
2225
  target.preloadTimeout = null;
2318
2226
  }
2319
2227
  };
2320
-
2321
2228
  return {
2322
2229
  type: 'internal',
2323
2230
  next,
@@ -2331,21 +2238,15 @@
2331
2238
  },
2332
2239
  buildNext: opts => {
2333
2240
  const next = router.__.buildLocation(opts);
2334
-
2335
2241
  const matches = router.matchRoutes(next.pathname);
2336
-
2337
2242
  const __preSearchFilters = matches.map(match => {
2338
2243
  var _match$options$preSea;
2339
-
2340
2244
  return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
2341
2245
  }).flat().filter(Boolean);
2342
-
2343
2246
  const __postSearchFilters = matches.map(match => {
2344
2247
  var _match$options$postSe;
2345
-
2346
2248
  return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
2347
2249
  }).flat().filter(Boolean);
2348
-
2349
2250
  return router.__.buildLocation(_extends({}, opts, {
2350
2251
  __preSearchFilters,
2351
2252
  __postSearchFilters
@@ -2356,18 +2257,12 @@
2356
2257
  const recurseRoutes = (routeConfigs, parent) => {
2357
2258
  return routeConfigs.map(routeConfig => {
2358
2259
  const routeOptions = routeConfig.options;
2359
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
2360
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
2361
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
2362
- // }
2363
-
2260
+ const route = createRoute(routeConfig, routeOptions, parent, router);
2364
2261
  const existingRoute = router.routesById[route.routeId];
2365
-
2366
2262
  if (existingRoute) {
2367
2263
  {
2368
2264
  console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
2369
2265
  }
2370
-
2371
2266
  throw new Error();
2372
2267
  }
2373
2268
  router.routesById[route.routeId] = route;
@@ -2376,13 +2271,11 @@
2376
2271
  return route;
2377
2272
  });
2378
2273
  };
2379
-
2380
2274
  const routes = recurseRoutes([rootRouteConfig]);
2381
2275
  return routes[0];
2382
2276
  },
2383
2277
  parseLocation: (location, previousLocation) => {
2384
2278
  var _location$hash$split$;
2385
-
2386
2279
  const parsedSearch = router.options.parseSearch(location.search);
2387
2280
  return {
2388
2281
  pathname: location.pathname,
@@ -2400,41 +2293,36 @@
2400
2293
  },
2401
2294
  buildLocation: function buildLocation(dest) {
2402
2295
  var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
2403
-
2404
2296
  if (dest === void 0) {
2405
2297
  dest = {};
2406
2298
  }
2407
-
2408
2299
  // const resolvedFrom: Location = {
2409
2300
  // ...router.location,
2410
2301
  const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
2411
-
2412
2302
  let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
2413
-
2414
2303
  const fromMatches = router.matchRoutes(router.location.pathname, {
2415
2304
  strictParseParams: true
2416
2305
  });
2417
2306
  const toMatches = router.matchRoutes(pathname);
2418
-
2419
2307
  const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
2420
-
2421
2308
  let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2422
-
2423
2309
  if (nextParams) {
2424
2310
  toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2425
2311
  Object.assign({}, nextParams, fn(nextParams));
2426
2312
  });
2427
2313
  }
2314
+ pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
2428
2315
 
2429
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
2430
-
2431
- 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
2316
+ // Pre filters first
2317
+ const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search;
2432
2318
 
2319
+ // Then the link/navigate function
2433
2320
  const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2434
2321
  : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
2435
2322
  : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2436
- : {}; // Then post filters
2323
+ : {};
2437
2324
 
2325
+ // Then post filters
2438
2326
  const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2439
2327
  const search = replaceEqualDeep(router.location.search, postFilteredSearch);
2440
2328
  const searchStr = router.options.stringifySearch(search);
@@ -2454,25 +2342,21 @@
2454
2342
  const id = '' + Date.now() + Math.random();
2455
2343
  if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
2456
2344
  let nextAction = 'replace';
2457
-
2458
2345
  if (!replace) {
2459
2346
  nextAction = 'push';
2460
2347
  }
2461
-
2462
2348
  const isSameUrl = router.__.parseLocation(history.location).href === next.href;
2463
-
2464
2349
  if (isSameUrl && !next.key) {
2465
2350
  nextAction = 'replace';
2466
2351
  }
2467
-
2468
2352
  if (nextAction === 'replace') {
2469
2353
  history.replace({
2470
2354
  pathname: next.pathname,
2471
2355
  hash: next.hash,
2472
2356
  search: next.searchStr
2473
- }, {
2357
+ }, _extends({
2474
2358
  id
2475
- });
2359
+ }, next.state));
2476
2360
  } else {
2477
2361
  history.push({
2478
2362
  pathname: next.pathname,
@@ -2482,48 +2366,75 @@
2482
2366
  id
2483
2367
  });
2484
2368
  }
2485
-
2486
2369
  router.navigationPromise = new Promise(resolve => {
2487
2370
  const previousNavigationResolve = router.resolveNavigation;
2488
-
2489
2371
  router.resolveNavigation = () => {
2490
2372
  previousNavigationResolve();
2491
2373
  resolve();
2374
+ delete router.navigationPromise;
2492
2375
  };
2493
2376
  });
2494
2377
  return router.navigationPromise;
2495
2378
  }
2496
2379
  }
2497
2380
  };
2498
- router.location = router.__.parseLocation(history.location);
2499
- router.state.location = router.location;
2500
- router.update(userOptions); // Allow frameworks to hook into the router creation
2381
+ router.update(userOptions);
2501
2382
 
2383
+ // Allow frameworks to hook into the router creation
2502
2384
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
2503
2385
  return router;
2504
2386
  }
2505
-
2506
2387
  function isCtrlEvent(e) {
2507
2388
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2508
2389
  }
2390
+ function cascadeLoaderData(matches) {
2391
+ matches.forEach((match, index) => {
2392
+ const parent = matches[index - 1];
2393
+ if (parent) {
2394
+ match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
2395
+ }
2396
+ });
2397
+ }
2509
2398
 
2510
2399
  const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
2511
- _excluded2 = ["pending", "caseSensitive", "children"],
2512
- _excluded3 = ["children", "router"];
2400
+ _excluded2 = ["pending", "caseSensitive", "children"],
2401
+ _excluded3 = ["router"];
2402
+ function lazy(importer) {
2403
+ const lazyComp = /*#__PURE__*/React__namespace.lazy(importer);
2404
+ let promise;
2405
+ let resolvedComp;
2406
+ const forwardedComp = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2407
+ const resolvedCompRef = React__namespace.useRef(resolvedComp || lazyComp);
2408
+ return /*#__PURE__*/React__namespace.createElement(resolvedCompRef.current, _extends$2({}, ref ? {
2409
+ ref
2410
+ } : {}, props));
2411
+ });
2412
+ const finalComp = forwardedComp;
2413
+ finalComp.preload = () => {
2414
+ if (!promise) {
2415
+ promise = importer().then(module => {
2416
+ resolvedComp = module.default;
2417
+ return resolvedComp;
2418
+ });
2419
+ }
2420
+ return promise;
2421
+ };
2422
+ return finalComp;
2423
+ }
2513
2424
  //
2514
- const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2515
- const routerContext = /*#__PURE__*/React__namespace.createContext(null); // Detect if we're in the DOM
2516
2425
 
2517
- const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
2518
- const useLayoutEffect = isDOM ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2426
+ function Link(props) {
2427
+ const router = useRouter();
2428
+ return /*#__PURE__*/React__namespace.createElement(router.Link, props);
2429
+ }
2430
+ const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2431
+ const routerContext = /*#__PURE__*/React__namespace.createContext(null);
2519
2432
  function MatchesProvider(props) {
2520
2433
  return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, props);
2521
2434
  }
2522
-
2523
2435
  const useRouterSubscription = router => {
2524
2436
  shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
2525
2437
  };
2526
-
2527
2438
  function createReactRouter(opts) {
2528
2439
  const makeRouteExt = (route, router) => {
2529
2440
  return {
@@ -2531,7 +2442,6 @@
2531
2442
  if (subRouteId === void 0) {
2532
2443
  subRouteId = '.';
2533
2444
  }
2534
-
2535
2445
  const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
2536
2446
  const resolvedRoute = router.getRoute(resolvedRouteId);
2537
2447
  useRouterSubscription(router);
@@ -2540,27 +2450,25 @@
2540
2450
  },
2541
2451
  linkProps: options => {
2542
2452
  var _functionalUpdate, _functionalUpdate2;
2543
-
2544
2453
  const {
2545
- // custom props
2546
- target,
2547
- activeProps = () => ({
2548
- className: 'active'
2549
- }),
2550
- inactiveProps = () => ({}),
2551
- disabled,
2552
- // element props
2553
- style,
2554
- className,
2555
- onClick,
2556
- onFocus,
2557
- onMouseEnter,
2558
- onMouseLeave
2559
- } = options,
2560
- rest = _objectWithoutPropertiesLoose(options, _excluded);
2561
-
2454
+ // custom props
2455
+
2456
+ target,
2457
+ activeProps = () => ({
2458
+ className: 'active'
2459
+ }),
2460
+ inactiveProps = () => ({}),
2461
+ disabled,
2462
+ // element props
2463
+ style,
2464
+ className,
2465
+ onClick,
2466
+ onFocus,
2467
+ onMouseEnter,
2468
+ onMouseLeave
2469
+ } = options,
2470
+ rest = _objectWithoutPropertiesLoose(options, _excluded);
2562
2471
  const linkInfo = route.buildLink(options);
2563
-
2564
2472
  if (linkInfo.type === 'external') {
2565
2473
  const {
2566
2474
  href
@@ -2569,7 +2477,6 @@
2569
2477
  href
2570
2478
  };
2571
2479
  }
2572
-
2573
2480
  const {
2574
2481
  handleClick,
2575
2482
  handleFocus,
@@ -2578,21 +2485,28 @@
2578
2485
  isActive,
2579
2486
  next
2580
2487
  } = linkInfo;
2581
-
2488
+ const reactHandleClick = e => {
2489
+ if (React__namespace.startTransition)
2490
+ // This is a hack for react < 18
2491
+ React__namespace.startTransition(() => {
2492
+ handleClick(e);
2493
+ });else handleClick(e);
2494
+ };
2582
2495
  const composeHandlers = handlers => e => {
2583
2496
  e.persist();
2584
2497
  handlers.forEach(handler => {
2585
2498
  if (handler) handler(e);
2586
2499
  });
2587
- }; // Get the active props
2588
-
2500
+ };
2589
2501
 
2590
- const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {}; // Get the inactive props
2502
+ // Get the active props
2503
+ const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {};
2591
2504
 
2505
+ // Get the inactive props
2592
2506
  const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
2593
2507
  return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
2594
2508
  href: disabled ? undefined : next.href,
2595
- onClick: composeHandlers([handleClick, onClick]),
2509
+ onClick: composeHandlers([reactHandleClick, onClick]),
2596
2510
  onFocus: composeHandlers([handleFocus, onFocus]),
2597
2511
  onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
2598
2512
  onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
@@ -2619,25 +2533,21 @@
2619
2533
  }),
2620
2534
  MatchRoute: opts => {
2621
2535
  const {
2622
- pending,
2623
- caseSensitive
2624
- } = opts,
2625
- rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2626
-
2536
+ pending,
2537
+ caseSensitive
2538
+ } = opts,
2539
+ rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2627
2540
  const params = route.matchRoute(rest, {
2628
2541
  pending,
2629
2542
  caseSensitive
2630
2543
  });
2631
-
2632
2544
  if (!params) {
2633
2545
  return null;
2634
2546
  }
2635
-
2636
2547
  return typeof opts.children === 'function' ? opts.children(params) : opts.children;
2637
2548
  }
2638
2549
  };
2639
2550
  };
2640
-
2641
2551
  const coreRouter = createRouter(_extends$2({}, opts, {
2642
2552
  createRouter: router => {
2643
2553
  const routerExt = {
@@ -2645,24 +2555,20 @@
2645
2555
  useRouterSubscription(router);
2646
2556
  return router.state;
2647
2557
  },
2648
- useMatch: routeId => {
2558
+ useMatch: (routeId, opts) => {
2559
+ var _opts$strict;
2649
2560
  useRouterSubscription(router);
2650
2561
  invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
2651
-
2652
- const runtimeMatch = _useMatch();
2653
-
2562
+ const nearestMatch = useNearestMatch();
2654
2563
  const match = router.state.matches.find(d => d.routeId === routeId);
2655
- invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
2656
- invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
2657
-
2658
- if (!match) {
2659
- invariant('Match not found!');
2564
+ if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
2565
+ invariant(match, "Could not find an active match for \"" + routeId + "\"!");
2566
+ invariant(nearestMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch(\"" + (match == null ? void 0 : match.routeId) + "\") is being called in a component that is meant to render the '" + nearestMatch.routeId + "' route. Did you mean to 'useMatch(\"" + (match == null ? void 0 : match.routeId) + "\", { strict: false })' or 'useRoute(\"" + (match == null ? void 0 : match.routeId) + "\")' instead?");
2660
2567
  }
2661
-
2662
2568
  return match;
2663
2569
  }
2664
2570
  };
2665
- const routeExt = makeRouteExt(router.getRoute('/'), router);
2571
+ const routeExt = makeRouteExt(router.getRoute(rootRouteId), router);
2666
2572
  Object.assign(router, routerExt, routeExt);
2667
2573
  },
2668
2574
  createRoute: _ref => {
@@ -2673,169 +2579,157 @@
2673
2579
  const routeExt = makeRouteExt(route, router);
2674
2580
  Object.assign(route, routeExt);
2675
2581
  },
2676
- createElement: async element => {
2677
- if (typeof element === 'function') {
2678
- const res = await element(); // Support direct import() calls
2679
-
2680
- if (typeof res === 'object' && res.default) {
2681
- return /*#__PURE__*/React__namespace.createElement(res.default);
2682
- } else {
2683
- return res;
2684
- }
2582
+ loadComponent: async component => {
2583
+ if (component.preload && typeof document !== 'undefined') {
2584
+ component.preload();
2585
+ // return await component.preload()
2685
2586
  }
2686
2587
 
2687
- return element;
2588
+ return component;
2688
2589
  }
2689
2590
  }));
2690
2591
  return coreRouter;
2691
2592
  }
2692
2593
  function RouterProvider(_ref2) {
2693
2594
  let {
2694
- children,
2695
- router
2696
- } = _ref2,
2697
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2698
-
2595
+ router
2596
+ } = _ref2,
2597
+ rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2699
2598
  router.update(rest);
2700
2599
  useRouterSubscription(router);
2701
- useLayoutEffect(() => {
2600
+ React__namespace.useEffect(() => {
2702
2601
  return router.mount();
2703
2602
  }, [router]);
2704
- return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
2603
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
2705
2604
  value: {
2706
- router
2605
+ router: router
2707
2606
  }
2708
2607
  }, /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2709
- value: router.state.matches
2710
- }, children != null ? children : /*#__PURE__*/React__namespace.createElement(Outlet, null)));
2608
+ value: [undefined, ...router.state.matches]
2609
+ }, /*#__PURE__*/React__namespace.createElement(Outlet, null))));
2711
2610
  }
2712
-
2713
2611
  function useRouter() {
2714
2612
  const value = React__namespace.useContext(routerContext);
2715
2613
  warning(!value, 'useRouter must be used inside a <Router> component!');
2716
2614
  useRouterSubscription(value.router);
2717
2615
  return value.router;
2718
2616
  }
2719
-
2720
2617
  function useMatches() {
2721
2618
  return React__namespace.useContext(matchesContext);
2722
- } // function useParentMatches(): RouteMatch[] {
2723
- // const router = useRouter()
2724
- // const match = useMatch()
2725
- // const matches = router.state.matches
2726
- // return matches.slice(
2727
- // 0,
2728
- // matches.findIndex((d) => d.matchId === match.matchId) - 1,
2729
- // )
2730
- // }
2731
-
2732
-
2733
- function _useMatch() {
2734
- var _useMatches;
2735
-
2736
- return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
2737
2619
  }
2738
-
2620
+ function useMatch(routeId, opts) {
2621
+ const router = useRouter();
2622
+ return router.useMatch(routeId, opts);
2623
+ }
2624
+ function useNearestMatch() {
2625
+ const runtimeMatch = useMatches()[0];
2626
+ invariant(runtimeMatch, "Could not find a nearest match!");
2627
+ return runtimeMatch;
2628
+ }
2629
+ function useRoute(routeId) {
2630
+ const router = useRouter();
2631
+ return router.useRoute(routeId);
2632
+ }
2633
+ function useSearch(_routeId) {
2634
+ return useRouter().state.location.search;
2635
+ }
2636
+ function linkProps(props) {
2637
+ const router = useRouter();
2638
+ return router.linkProps(props);
2639
+ }
2640
+ function MatchRoute(props) {
2641
+ const router = useRouter();
2642
+ return /*#__PURE__*/React__namespace.createElement(router.MatchRoute, props);
2643
+ }
2739
2644
  function Outlet() {
2740
- var _childMatch$options$c;
2741
-
2645
+ var _ref3, _match$__$pendingComp, _match$__$errorCompon;
2742
2646
  const router = useRouter();
2743
- const [, ...matches] = useMatches();
2744
- const childMatch = matches[0];
2745
- if (!childMatch) return null;
2746
-
2747
- const element = (() => {
2748
- var _childMatch$__$errorE, _ref4;
2749
-
2750
- if (!childMatch) {
2751
- return null;
2752
- }
2753
-
2754
- const errorElement = (_childMatch$__$errorE = childMatch.__.errorElement) != null ? _childMatch$__$errorE : router.options.defaultErrorElement;
2755
-
2756
- if (childMatch.status === 'error') {
2757
- if (errorElement) {
2758
- return errorElement;
2759
- }
2760
-
2761
- if (childMatch.options.useErrorBoundary || router.options.useErrorBoundary) {
2762
- throw childMatch.error;
2763
- }
2764
-
2765
- return /*#__PURE__*/React__namespace.createElement(DefaultErrorBoundary, {
2766
- error: childMatch.error
2767
- });
2768
- }
2769
-
2770
- if (childMatch.status === 'loading' || childMatch.status === 'idle') {
2771
- if (childMatch.isPending) {
2772
- var _childMatch$__$pendin;
2773
-
2774
- const pendingElement = (_childMatch$__$pendin = childMatch.__.pendingElement) != null ? _childMatch$__$pendin : router.options.defaultPendingElement;
2775
-
2776
- if (childMatch.options.pendingMs || pendingElement) {
2777
- var _ref3;
2778
-
2779
- return (_ref3 = pendingElement) != null ? _ref3 : null;
2780
- }
2781
- }
2782
-
2783
- return null;
2784
- }
2785
-
2786
- return (_ref4 = childMatch.__.element) != null ? _ref4 : router.options.defaultElement;
2787
- })();
2788
-
2789
- const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
2647
+ const matches = useMatches().slice(1);
2648
+ const match = matches[0];
2649
+ const defaultPending = React__namespace.useCallback(() => null, []);
2650
+ if (!match) {
2651
+ return null;
2652
+ }
2653
+ const PendingComponent = (_ref3 = (_match$__$pendingComp = match.__.pendingComponent) != null ? _match$__$pendingComp : router.options.defaultPendingComponent) != null ? _ref3 : defaultPending;
2654
+ const errorComponent = (_match$__$errorCompon = match.__.errorComponent) != null ? _match$__$errorCompon : router.options.defaultErrorComponent;
2790
2655
  return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2791
- value: matches,
2792
- key: childMatch.matchId
2656
+ value: matches
2657
+ }, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
2658
+ fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, null)
2793
2659
  }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2794
- catchElement: catchElement
2795
- }, element));
2660
+ key: match.routeId,
2661
+ errorComponent: errorComponent,
2662
+ match: match
2663
+ }, (() => {
2664
+ if (match.status === 'error') {
2665
+ throw match.error;
2666
+ }
2667
+ if (match.status === 'success') {
2668
+ var _ref4, _ref5;
2669
+ return /*#__PURE__*/React__namespace.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
2670
+ }
2671
+ throw match.__.loadPromise;
2672
+ })())));
2796
2673
  }
2797
-
2798
2674
  class CatchBoundary extends React__namespace.Component {
2799
2675
  constructor() {
2800
2676
  super(...arguments);
2801
2677
  this.state = {
2802
- error: false
2803
- };
2804
-
2805
- this.reset = () => {
2806
- this.setState({
2807
- error: false,
2808
- info: false
2809
- });
2678
+ error: false,
2679
+ info: undefined
2810
2680
  };
2811
2681
  }
2812
-
2813
2682
  componentDidCatch(error, info) {
2683
+ console.error("Error in route match: " + this.props.match.matchId);
2814
2684
  console.error(error);
2815
2685
  this.setState({
2816
2686
  error,
2817
2687
  info
2818
2688
  });
2819
2689
  }
2820
-
2821
2690
  render() {
2822
- var _this$props$catchElem;
2823
-
2824
- const catchElement = (_this$props$catchElem = this.props.catchElement) != null ? _this$props$catchElem : DefaultErrorBoundary;
2691
+ return /*#__PURE__*/React__namespace.createElement(CatchBoundaryInner, _extends$2({}, this.props, {
2692
+ errorState: this.state,
2693
+ reset: () => this.setState({})
2694
+ }));
2695
+ }
2696
+ }
2825
2697
 
2826
- if (this.state.error) {
2827
- return typeof catchElement === 'function' ? catchElement(this.state) : catchElement;
2698
+ // This is the messiest thing ever... I'm either seriously tired (likely) or
2699
+ // there has to be a better way to reset error boundaries when the
2700
+ // router's location key changes.
2701
+ function CatchBoundaryInner(props) {
2702
+ var _props$errorComponent;
2703
+ const [activeErrorState, setActiveErrorState] = React__namespace.useState(props.errorState);
2704
+ const router = useRouter();
2705
+ const errorComponent = (_props$errorComponent = props.errorComponent) != null ? _props$errorComponent : DefaultErrorBoundary;
2706
+ React__namespace.useEffect(() => {
2707
+ if (activeErrorState) {
2708
+ let prevKey = router.state.location.key;
2709
+ return router.subscribe(() => {
2710
+ if (router.state.location.key !== prevKey) {
2711
+ prevKey = router.state.location.key;
2712
+ setActiveErrorState({});
2713
+ }
2714
+ });
2828
2715
  }
2829
-
2830
- return this.props.children;
2716
+ return;
2717
+ }, [activeErrorState]);
2718
+ React__namespace.useEffect(() => {
2719
+ if (props.errorState.error) {
2720
+ setActiveErrorState(props.errorState);
2721
+ }
2722
+ props.reset();
2723
+ }, [props.errorState.error]);
2724
+ if (activeErrorState.error) {
2725
+ return /*#__PURE__*/React__namespace.createElement(errorComponent, activeErrorState);
2831
2726
  }
2832
-
2727
+ return props.children;
2833
2728
  }
2834
-
2835
- function DefaultErrorBoundary(_ref5) {
2729
+ function DefaultErrorBoundary(_ref6) {
2836
2730
  let {
2837
2731
  error
2838
- } = _ref5;
2732
+ } = _ref6;
2839
2733
  return /*#__PURE__*/React__namespace.createElement("div", {
2840
2734
  style: {
2841
2735
  padding: '.5rem',
@@ -2857,18 +2751,7 @@
2857
2751
  padding: '.5rem',
2858
2752
  color: 'red'
2859
2753
  }
2860
- }, error.message) : null)), /*#__PURE__*/React__namespace.createElement("div", {
2861
- style: {
2862
- height: '1rem'
2863
- }
2864
- }), /*#__PURE__*/React__namespace.createElement("div", {
2865
- style: {
2866
- fontSize: '.8em',
2867
- borderLeft: '3px solid rgba(127, 127, 127, 1)',
2868
- paddingLeft: '.5rem',
2869
- opacity: 0.5
2870
- }
2871
- }, "If you are the owner of this website, it's highly recommended that you configure your own custom Catch/Error boundaries for the router. You can optionally configure a boundary for each route."));
2754
+ }, error.message) : null)));
2872
2755
  }
2873
2756
  function usePrompt(message, when) {
2874
2757
  const router = useRouter();
@@ -2885,22 +2768,23 @@
2885
2768
  return unblock;
2886
2769
  }, [when, location, message]);
2887
2770
  }
2888
- function Prompt(_ref6) {
2771
+ function Prompt(_ref7) {
2889
2772
  let {
2890
2773
  message,
2891
2774
  when,
2892
2775
  children
2893
- } = _ref6;
2776
+ } = _ref7;
2894
2777
  usePrompt(message, when != null ? when : true);
2895
2778
  return children != null ? children : null;
2896
2779
  }
2897
2780
 
2898
2781
  exports.DefaultErrorBoundary = DefaultErrorBoundary;
2782
+ exports.Link = Link;
2783
+ exports.MatchRoute = MatchRoute;
2899
2784
  exports.MatchesProvider = MatchesProvider;
2900
2785
  exports.Outlet = Outlet;
2901
2786
  exports.Prompt = Prompt;
2902
2787
  exports.RouterProvider = RouterProvider;
2903
- exports.cascadeLoaderData = cascadeLoaderData;
2904
2788
  exports.cleanPath = cleanPath;
2905
2789
  exports.createBrowserHistory = createBrowserHistory;
2906
2790
  exports.createHashHistory = createHashHistory;
@@ -2919,18 +2803,29 @@
2919
2803
  exports.invariant = invariant;
2920
2804
  exports.joinPaths = joinPaths;
2921
2805
  exports.last = last;
2806
+ exports.lazy = lazy;
2807
+ exports.linkProps = linkProps;
2922
2808
  exports.matchByPath = matchByPath;
2923
2809
  exports.matchPathname = matchPathname;
2810
+ exports.matchesContext = matchesContext;
2924
2811
  exports.parsePathname = parsePathname;
2925
2812
  exports.parseSearchWith = parseSearchWith;
2813
+ exports.pick = pick;
2926
2814
  exports.replaceEqualDeep = replaceEqualDeep;
2927
2815
  exports.resolvePath = resolvePath;
2928
2816
  exports.rootRouteId = rootRouteId;
2817
+ exports.routerContext = routerContext;
2929
2818
  exports.stringifySearchWith = stringifySearchWith;
2930
2819
  exports.trimPath = trimPath;
2931
2820
  exports.trimPathLeft = trimPathLeft;
2932
2821
  exports.trimPathRight = trimPathRight;
2822
+ exports.useMatch = useMatch;
2823
+ exports.useMatches = useMatches;
2824
+ exports.useNearestMatch = useNearestMatch;
2933
2825
  exports.usePrompt = usePrompt;
2826
+ exports.useRoute = useRoute;
2827
+ exports.useRouter = useRouter;
2828
+ exports.useSearch = useSearch;
2934
2829
  exports.warning = warning;
2935
2830
 
2936
2831
  Object.defineProperty(exports, '__esModule', { value: true });