@tanstack/router-core 0.0.1-beta.25 → 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.
Files changed (52) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -2
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/{packages/router-core/src/index.js → index.js} +22 -6
  4. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  5. package/build/cjs/{packages/router-core/src/path.js → path.js} +6 -30
  6. package/build/cjs/path.js.map +1 -0
  7. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  8. package/build/cjs/qss.js.map +1 -0
  9. package/build/cjs/{packages/router-core/src/route.js → route.js} +7 -16
  10. package/build/cjs/route.js.map +1 -0
  11. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -12
  12. package/build/cjs/routeConfig.js.map +1 -0
  13. package/build/cjs/{packages/router-core/src/routeMatch.js → routeMatch.js} +15 -35
  14. package/build/cjs/routeMatch.js.map +1 -0
  15. package/build/cjs/{packages/router-core/src/router.js → router.js} +103 -159
  16. package/build/cjs/router.js.map +1 -0
  17. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
  18. package/build/cjs/searchParams.js.map +1 -0
  19. package/build/cjs/{packages/router-core/src/utils.js → utils.js} +10 -24
  20. package/build/cjs/utils.js.map +1 -0
  21. package/build/esm/index.js +156 -1116
  22. package/build/esm/index.js.map +1 -1
  23. package/build/stats-html.html +59 -49
  24. package/build/stats-react.json +160 -154
  25. package/build/types/index.d.ts +53 -40
  26. package/build/umd/index.development.js +151 -294
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/link.ts +2 -2
  32. package/src/path.ts +2 -2
  33. package/src/route.ts +8 -5
  34. package/src/routeConfig.ts +77 -63
  35. package/src/routeInfo.ts +11 -6
  36. package/src/routeMatch.ts +1 -1
  37. package/src/router.ts +114 -51
  38. package/src/utils.ts +2 -2
  39. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  40. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  41. package/build/cjs/node_modules/history/index.js +0 -815
  42. package/build/cjs/node_modules/history/index.js.map +0 -1
  43. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  44. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  45. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  46. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  47. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  48. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  49. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  50. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  52. 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
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
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
- } // If has modified constructor
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
- } // If has modified prototype
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
- } // If constructor does not have an Object-specific method
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
- } // Most likely a plain Object
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
- } // Remove empty segments and '.' segments
1001
-
979
+ }
1002
980
 
981
+ // Remove empty segments and '.' segments
1003
982
  const split = pathname.split('/').filter(Boolean);
1004
983
  segments.push(...split.map(part => {
1005
984
  if (part.startsWith('*')) {
@@ -1008,20 +987,17 @@
1008
987
  value: part
1009
988
  };
1010
989
  }
1011
-
1012
- if (part.charAt(0) === ':') {
990
+ if (part.charAt(0) === '$') {
1013
991
  return {
1014
992
  type: 'param',
1015
993
  value: part
1016
994
  };
1017
995
  }
1018
-
1019
996
  return {
1020
997
  type: 'pathname',
1021
998
  value: part
1022
999
  };
1023
1000
  }));
1024
-
1025
1001
  if (pathname.slice(-1) === '/') {
1026
1002
  pathname = pathname.substring(1);
1027
1003
  segments.push({
@@ -1029,7 +1005,6 @@
1029
1005
  value: '/'
1030
1006
  });
1031
1007
  }
1032
-
1033
1008
  return segments;
1034
1009
  }
1035
1010
  function interpolatePath(path, params, leaveWildcard) {
@@ -1038,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); // const searchMatched = matchBySearch(currentLocation.search, 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
- if (!baseSegment.value.startsWith(':')) {
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
- i,
1131
- tmp,
1132
- str = '';
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
- k,
1163
- out = {},
1164
- arr = str.split('&');
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); // router.state = {
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); // router.removeActionQueue.push({ loader, 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
- } // Strip the root from parentIds
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
- let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
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,
@@ -1368,9 +1306,11 @@
1368
1306
  fullPath: fullPath,
1369
1307
  options: options,
1370
1308
  children,
1371
- createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
1372
1309
  addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
1373
- createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
1310
+ createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
1311
+ generate: () => {
1312
+ invariant(false, "routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. ");
1313
+ }
1374
1314
  };
1375
1315
  };
1376
1316
 
@@ -1398,31 +1338,26 @@
1398
1338
  resolve: () => {},
1399
1339
  notify: () => {
1400
1340
  routeMatch.__.resolve();
1401
-
1402
1341
  routeMatch.router.notify();
1403
1342
  },
1404
1343
  validate: () => {
1405
1344
  var _routeMatch$parentMat, _routeMatch$parentMat2;
1406
-
1407
1345
  // Validate the search params and stabilize them
1408
1346
  const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1409
-
1410
1347
  try {
1411
1348
  var _validator;
1412
-
1413
1349
  const prevSearch = routeMatch.routeSearch;
1414
1350
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1415
- let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
1351
+ let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
1416
1352
 
1353
+ // Invalidate route matches when search param stability changes
1417
1354
  if (prevSearch !== nextSearch) {
1418
1355
  routeMatch.isInvalid = true;
1419
1356
  }
1420
-
1421
1357
  routeMatch.routeSearch = nextSearch;
1422
1358
  routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1423
1359
  componentTypes.map(async type => {
1424
1360
  const component = routeMatch.options[type];
1425
-
1426
1361
  if (typeof routeMatch.__[type] !== 'function') {
1427
1362
  routeMatch.__[type] = component;
1428
1363
  }
@@ -1434,15 +1369,14 @@
1434
1369
  });
1435
1370
  error.code = 'INVALID_SEARCH_PARAMS';
1436
1371
  routeMatch.status = 'error';
1437
- routeMatch.error = error; // Do not proceed with loading the route
1438
-
1372
+ routeMatch.error = error;
1373
+ // Do not proceed with loading the route
1439
1374
  return;
1440
1375
  }
1441
1376
  }
1442
1377
  },
1443
1378
  cancel: () => {
1444
1379
  var _routeMatch$__$abortC;
1445
-
1446
1380
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1447
1381
  },
1448
1382
  invalidate: () => {
@@ -1451,27 +1385,26 @@
1451
1385
  hasLoaders: () => {
1452
1386
  return !!(route.options.loader || componentTypes.some(d => {
1453
1387
  var _route$options$d;
1454
-
1455
1388
  return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
1456
1389
  }));
1457
1390
  },
1458
1391
  load: async loaderOpts => {
1459
1392
  const now = Date.now();
1460
- 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
1393
+ const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
1461
1394
 
1395
+ // If this is a preload, add it to the preload cache
1462
1396
  if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
1463
1397
  // If the match is currently active, don't preload it
1464
1398
  if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
1465
1399
  return;
1466
1400
  }
1467
-
1468
1401
  router.matchCache[routeMatch.matchId] = {
1469
1402
  gc: now + loaderOpts.gcMaxAge,
1470
1403
  match: routeMatch
1471
1404
  };
1472
- } // If the match is invalid, errored or idle, trigger it to load
1473
-
1405
+ }
1474
1406
 
1407
+ // If the match is invalid, errored or idle, trigger it to load
1475
1408
  if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1476
1409
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1477
1410
  await routeMatch.fetch({
@@ -1482,53 +1415,47 @@
1482
1415
  fetch: async opts => {
1483
1416
  const loadId = '' + Date.now() + Math.random();
1484
1417
  routeMatch.__.latestId = loadId;
1485
-
1486
1418
  const checkLatest = async () => {
1487
1419
  if (loadId !== routeMatch.__.latestId) {
1488
1420
  // warning(true, 'Data loader is out of date!')
1489
1421
  return new Promise(() => {});
1490
1422
  }
1491
- }; // If the match was in an error state, set it
1423
+ };
1424
+
1425
+ // If the match was in an error state, set it
1492
1426
  // to a loading state again. Otherwise, keep it
1493
1427
  // as loading or resolved
1494
-
1495
-
1496
1428
  if (routeMatch.status === 'idle') {
1497
1429
  routeMatch.status = 'loading';
1498
- } // We started loading the route, so it's no longer invalid
1499
-
1430
+ }
1500
1431
 
1432
+ // We started loading the route, so it's no longer invalid
1501
1433
  routeMatch.isInvalid = false;
1502
1434
  routeMatch.__.loadPromise = new Promise(async resolve => {
1503
1435
  // We are now fetching, even if it's in the background of a
1504
1436
  // resolved state
1505
1437
  routeMatch.isFetching = true;
1506
1438
  routeMatch.__.resolve = resolve;
1507
-
1508
1439
  routeMatch.__.componentsPromise = (async () => {
1509
1440
  // then run all component and data loaders in parallel
1510
1441
  // For each component type, potentially load it asynchronously
1442
+
1511
1443
  await Promise.all(componentTypes.map(async type => {
1512
1444
  var _routeMatch$__$type;
1513
-
1514
1445
  const component = routeMatch.options[type];
1515
-
1516
1446
  if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
1517
1447
  routeMatch.__[type] = await router.options.loadComponent(component);
1518
1448
  }
1519
1449
  }));
1520
1450
  })();
1521
-
1522
1451
  routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1523
1452
  try {
1524
1453
  var _ref, _ref2, _opts$maxAge;
1525
-
1526
1454
  if (routeMatch.options.loader) {
1527
1455
  const data = await router.loadMatchData(routeMatch);
1528
1456
  await checkLatest();
1529
1457
  routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1530
1458
  }
1531
-
1532
1459
  routeMatch.error = undefined;
1533
1460
  routeMatch.status = 'success';
1534
1461
  routeMatch.updatedAt = Date.now();
@@ -1536,26 +1463,21 @@
1536
1463
  return routeMatch.routeLoaderData;
1537
1464
  } catch (err) {
1538
1465
  await checkLatest();
1539
-
1540
1466
  {
1541
1467
  console.error(err);
1542
1468
  }
1543
-
1544
1469
  routeMatch.error = err;
1545
1470
  routeMatch.status = 'error';
1546
1471
  routeMatch.updatedAt = Date.now();
1547
1472
  throw err;
1548
1473
  }
1549
1474
  });
1550
-
1551
1475
  const after = async () => {
1552
1476
  await checkLatest();
1553
1477
  routeMatch.isFetching = false;
1554
1478
  delete routeMatch.__.loadPromise;
1555
-
1556
1479
  routeMatch.__.notify();
1557
1480
  };
1558
-
1559
1481
  try {
1560
1482
  await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
1561
1483
  after();
@@ -1567,11 +1489,9 @@
1567
1489
  await checkLatest();
1568
1490
  }
1569
1491
  });
1570
-
1571
1492
  if (!routeMatch.hasLoaders()) {
1572
1493
  routeMatch.status = 'success';
1573
1494
  }
1574
-
1575
1495
  return routeMatch;
1576
1496
  }
1577
1497
 
@@ -1582,42 +1502,39 @@
1582
1502
  if (searchStr.substring(0, 1) === '?') {
1583
1503
  searchStr = searchStr.substring(1);
1584
1504
  }
1505
+ let query = decode(searchStr);
1585
1506
 
1586
- let query = decode(searchStr); // Try to parse any query params that might be json
1587
-
1507
+ // Try to parse any query params that might be json
1588
1508
  for (let key in query) {
1589
1509
  const value = query[key];
1590
-
1591
1510
  if (typeof value === 'string') {
1592
1511
  try {
1593
1512
  query[key] = parser(value);
1594
- } catch (err) {//
1513
+ } catch (err) {
1514
+ //
1595
1515
  }
1596
1516
  }
1597
1517
  }
1598
-
1599
1518
  return query;
1600
1519
  };
1601
1520
  }
1602
1521
  function stringifySearchWith(stringify) {
1603
1522
  return search => {
1604
1523
  search = _extends({}, search);
1605
-
1606
1524
  if (search) {
1607
1525
  Object.keys(search).forEach(key => {
1608
1526
  const val = search[key];
1609
-
1610
1527
  if (typeof val === 'undefined' || val === undefined) {
1611
1528
  delete search[key];
1612
1529
  } else if (val && typeof val === 'object' && val !== null) {
1613
1530
  try {
1614
1531
  search[key] = stringify(val);
1615
- } catch (err) {// silent
1532
+ } catch (err) {
1533
+ // silent
1616
1534
  }
1617
1535
  }
1618
1536
  });
1619
1537
  }
1620
-
1621
1538
  const searchStr = encode(search).toString();
1622
1539
  return searchStr ? "?" + searchStr : '';
1623
1540
  };
@@ -1625,10 +1542,10 @@
1625
1542
 
1626
1543
  var _window$document;
1627
1544
  // Detect if we're in the DOM
1628
- const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
1545
+ const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
1629
1546
 
1547
+ // This is the default history object if none is defined
1630
1548
  const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
1631
-
1632
1549
  function getInitialRouterState() {
1633
1550
  return {
1634
1551
  status: 'idle',
@@ -1641,22 +1558,19 @@
1641
1558
  isPreloading: false
1642
1559
  };
1643
1560
  }
1644
-
1645
1561
  function createRouter(userOptions) {
1646
1562
  var _userOptions$stringif, _userOptions$parseSea;
1647
-
1648
1563
  const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
1649
-
1650
1564
  const originalOptions = _extends({
1651
1565
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
1652
1566
  defaultLoaderMaxAge: 0,
1653
1567
  defaultPreloadMaxAge: 2000,
1654
- defaultPreloadDelay: 50
1568
+ defaultPreloadDelay: 50,
1569
+ context: undefined
1655
1570
  }, userOptions, {
1656
1571
  stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1657
1572
  parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
1658
1573
  });
1659
-
1660
1574
  let router = {
1661
1575
  types: undefined,
1662
1576
  // public api
@@ -1664,13 +1578,11 @@
1664
1578
  options: originalOptions,
1665
1579
  listeners: [],
1666
1580
  // Resolved after construction
1667
- context: {},
1668
1581
  basepath: '',
1669
1582
  routeTree: undefined,
1670
1583
  routesById: {},
1671
1584
  location: undefined,
1672
1585
  //
1673
- navigationPromise: Promise.resolve(),
1674
1586
  resolveNavigation: () => {},
1675
1587
  matchCache: {},
1676
1588
  state: getInitialRouterState(),
@@ -1691,29 +1603,37 @@
1691
1603
  notify: () => {
1692
1604
  const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
1693
1605
  const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
1694
-
1695
1606
  if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
1696
1607
  router.state = _extends({}, router.state, {
1697
1608
  isFetching,
1698
1609
  isPreloading
1699
1610
  });
1700
1611
  }
1701
-
1702
1612
  cascadeLoaderData(router.state.matches);
1703
1613
  router.listeners.forEach(listener => listener(router));
1704
1614
  },
1705
- dehydrateState: () => {
1706
- return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
1707
- matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1708
- });
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
+ };
1709
1623
  },
1710
- hydrateState: dehydratedState => {
1624
+ hydrate: dehydratedState => {
1625
+ // Update the location
1626
+ router.location = dehydratedState.location;
1627
+
1628
+ // Update the context
1629
+ router.options.context = dehydratedState.context;
1630
+
1711
1631
  // Match the routes
1712
1632
  const matches = router.matchRoutes(router.location.pathname, {
1713
1633
  strictParseParams: true
1714
1634
  });
1715
1635
  matches.forEach((match, index) => {
1716
- const dehydratedMatch = dehydratedState.matches[index];
1636
+ const dehydratedMatch = dehydratedState.state.matches[index];
1717
1637
  invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1718
1638
  Object.assign(match, dehydratedMatch);
1719
1639
  });
@@ -1727,32 +1647,29 @@
1727
1647
  to: '.',
1728
1648
  search: true,
1729
1649
  hash: true
1730
- }); // If the current location isn't updated, trigger a navigation
1731
- // to the current location. Otherwise, load the current location.
1732
-
1650
+ });
1733
1651
 
1652
+ // If the current location isn't updated, trigger a navigation
1653
+ // to the current location. Otherwise, load the current location.
1734
1654
  if (next.href !== router.location.href) {
1735
1655
  router.__.commitLocation(next, true);
1736
1656
  }
1737
-
1738
1657
  if (!router.state.matches.length) {
1739
1658
  router.load();
1740
1659
  }
1741
-
1742
1660
  const unsub = router.history.listen(event => {
1743
1661
  router.load(router.__.parseLocation(event.location, router.location));
1744
- }); // addEventListener does not exist in React Native, but window does
1745
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1662
+ });
1746
1663
 
1664
+ // addEventListener does not exist in React Native, but window does
1665
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1747
1666
  if (!isServer && window.addEventListener) {
1748
1667
  // Listen to visibillitychange and focus
1749
1668
  window.addEventListener('visibilitychange', router.onFocus, false);
1750
1669
  window.addEventListener('focus', router.onFocus, false);
1751
1670
  }
1752
-
1753
1671
  return () => {
1754
1672
  unsub();
1755
-
1756
1673
  if (!isServer && window.removeEventListener) {
1757
1674
  // Be sure to unsubscribe if a new handler is set
1758
1675
  window.removeEventListener('visibilitychange', router.onFocus);
@@ -1765,28 +1682,23 @@
1765
1682
  },
1766
1683
  update: opts => {
1767
1684
  const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1768
-
1769
1685
  if (!router.location || newHistory) {
1770
1686
  if (opts != null && opts.history) {
1771
1687
  router.history = opts.history;
1772
1688
  }
1773
-
1774
1689
  router.location = router.__.parseLocation(router.history.location);
1775
1690
  router.state.location = router.location;
1776
1691
  }
1777
-
1778
1692
  Object.assign(router.options, opts);
1779
1693
  const {
1780
1694
  basepath,
1781
1695
  routeConfig
1782
1696
  } = router.options;
1783
1697
  router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
1784
-
1785
1698
  if (routeConfig) {
1786
1699
  router.routesById = {};
1787
1700
  router.routeTree = router.__.buildRouteTree(routeConfig);
1788
1701
  }
1789
-
1790
1702
  return router;
1791
1703
  },
1792
1704
  cancelMatches: () => {
@@ -1798,31 +1710,18 @@
1798
1710
  load: async next => {
1799
1711
  const id = Math.random();
1800
1712
  router.startedLoadingAt = id;
1801
-
1802
1713
  if (next) {
1803
1714
  // Ingest the new location
1804
1715
  router.location = next;
1805
- } // Cancel any pending matches
1806
-
1716
+ }
1807
1717
 
1808
- router.cancelMatches(); // Match the routes
1718
+ // Cancel any pending matches
1719
+ router.cancelMatches();
1809
1720
 
1721
+ // Match the routes
1810
1722
  const matches = router.matchRoutes(router.location.pathname, {
1811
1723
  strictParseParams: true
1812
- }); // Check if each match middleware to see if the route can be accessed
1813
-
1814
- try {
1815
- await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1816
- context: router.context
1817
- })));
1818
- } catch (err) {
1819
- if (err != null && err.then) {
1820
- await new Promise(() => {});
1821
- }
1822
-
1823
- throw err;
1824
- }
1825
-
1724
+ });
1826
1725
  if (typeof document !== 'undefined') {
1827
1726
  router.state = _extends({}, router.state, {
1828
1727
  pending: {
@@ -1839,18 +1738,29 @@
1839
1738
  });
1840
1739
  }
1841
1740
 
1842
- router.notify(); // Load the matches
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();
1843
1754
 
1755
+ // Load the matches
1844
1756
  await router.loadMatches(matches);
1845
-
1846
1757
  if (router.startedLoadingAt !== id) {
1847
1758
  // Ignore side-effects of match loading
1848
1759
  return router.navigationPromise;
1849
1760
  }
1850
-
1851
1761
  const previousMatches = router.state.matches;
1852
1762
  const exiting = [],
1853
- staying = [];
1763
+ staying = [];
1854
1764
  previousMatches.forEach(d => {
1855
1765
  if (matches.find(dd => dd.matchId === d.matchId)) {
1856
1766
  staying.push(d);
@@ -1864,19 +1774,17 @@
1864
1774
  const now = Date.now();
1865
1775
  exiting.forEach(d => {
1866
1776
  var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
1867
-
1868
1777
  d.__.onExit == null ? void 0 : d.__.onExit({
1869
1778
  params: d.params,
1870
1779
  search: d.routeSearch
1871
- }); // Clear idle error states when match leaves
1780
+ });
1872
1781
 
1782
+ // Clear idle error states when match leaves
1873
1783
  if (d.status === 'error' && !d.isFetching) {
1874
1784
  d.status = 'idle';
1875
1785
  d.error = undefined;
1876
1786
  }
1877
-
1878
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);
1879
-
1880
1788
  if (gc > 0) {
1881
1789
  router.matchCache[d.matchId] = {
1882
1790
  gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
@@ -1897,12 +1805,10 @@
1897
1805
  });
1898
1806
  delete router.matchCache[d.matchId];
1899
1807
  });
1900
-
1901
1808
  if (router.startedLoadingAt !== id) {
1902
1809
  // Ignore side-effects of match loading
1903
1810
  return;
1904
1811
  }
1905
-
1906
1812
  matches.forEach(match => {
1907
1813
  // Clear actions
1908
1814
  if (match.action) {
@@ -1922,18 +1828,19 @@
1922
1828
  cleanMatchCache: () => {
1923
1829
  const now = Date.now();
1924
1830
  Object.keys(router.matchCache).forEach(matchId => {
1925
- const entry = router.matchCache[matchId]; // Don't remove loading matches
1831
+ const entry = router.matchCache[matchId];
1926
1832
 
1833
+ // Don't remove loading matches
1927
1834
  if (entry.match.status === 'loading') {
1928
1835
  return;
1929
- } // Do not remove successful matches that are still valid
1930
-
1836
+ }
1931
1837
 
1838
+ // Do not remove successful matches that are still valid
1932
1839
  if (entry.gc > 0 && entry.gc > now) {
1933
1840
  return;
1934
- } // Everything else gets removed
1935
-
1841
+ }
1936
1842
 
1843
+ // Everything else gets removed
1937
1844
  delete router.matchCache[matchId];
1938
1845
  });
1939
1846
  },
@@ -1941,7 +1848,6 @@
1941
1848
  if (navigateOpts === void 0) {
1942
1849
  navigateOpts = router.location;
1943
1850
  }
1944
-
1945
1851
  const next = router.buildNext(navigateOpts);
1946
1852
  const matches = router.matchRoutes(next.pathname, {
1947
1853
  strictParseParams: true
@@ -1951,11 +1857,9 @@
1951
1857
  },
1952
1858
  preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
1953
1859
  var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
1954
-
1955
1860
  if (navigateOpts === void 0) {
1956
1861
  navigateOpts = router.location;
1957
1862
  }
1958
-
1959
1863
  const next = router.buildNext(navigateOpts);
1960
1864
  const matches = router.matchRoutes(next.pathname, {
1961
1865
  strictParseParams: true
@@ -1969,90 +1873,70 @@
1969
1873
  },
1970
1874
  matchRoutes: (pathname, opts) => {
1971
1875
  var _router$state$pending3, _router$state$pending4;
1972
-
1973
1876
  router.cleanMatchCache();
1974
1877
  const matches = [];
1975
-
1976
1878
  if (!router.routeTree) {
1977
1879
  return matches;
1978
1880
  }
1979
-
1980
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 : [])];
1981
-
1982
1882
  const recurse = async routes => {
1983
1883
  var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
1984
-
1985
1884
  const parentMatch = last(matches);
1986
1885
  let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
1987
1886
  const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
1988
1887
  let foundRoutes = [];
1989
-
1990
1888
  const findMatchInRoutes = (parentRoutes, routes) => {
1991
1889
  routes.some(route => {
1992
1890
  var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
1993
-
1994
1891
  if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
1995
1892
  return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
1996
1893
  }
1997
-
1998
1894
  const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
1999
1895
  const matchParams = matchPathname(pathname, {
2000
1896
  to: route.fullPath,
2001
1897
  fuzzy,
2002
1898
  caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
2003
1899
  });
2004
-
2005
1900
  if (matchParams) {
2006
1901
  let parsedParams;
2007
-
2008
1902
  try {
2009
1903
  var _route$options$parseP;
2010
-
2011
1904
  parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
2012
1905
  } catch (err) {
2013
1906
  if (opts != null && opts.strictParseParams) {
2014
1907
  throw err;
2015
1908
  }
2016
1909
  }
2017
-
2018
1910
  params = _extends({}, params, parsedParams);
2019
1911
  }
2020
-
2021
1912
  if (!!matchParams) {
2022
1913
  foundRoutes = [...parentRoutes, route];
2023
1914
  }
2024
-
2025
1915
  return !!foundRoutes.length;
2026
1916
  });
2027
1917
  return !!foundRoutes.length;
2028
1918
  };
2029
-
2030
1919
  findMatchInRoutes([], filteredRoutes);
2031
-
2032
1920
  if (!foundRoutes.length) {
2033
1921
  return;
2034
1922
  }
2035
-
2036
1923
  foundRoutes.forEach(foundRoute => {
2037
1924
  var _router$matchCache$ma;
2038
-
2039
1925
  const interpolatedPath = interpolatePath(foundRoute.routePath, params);
2040
1926
  const matchId = interpolatePath(foundRoute.routeId, params, true);
2041
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, {
2042
1928
  parentMatch,
2043
1929
  matchId,
2044
1930
  params,
2045
- pathname: joinPaths([pathname, interpolatedPath])
1931
+ pathname: joinPaths([router.basepath, interpolatedPath])
2046
1932
  });
2047
1933
  matches.push(match);
2048
1934
  });
2049
1935
  const foundRoute = last(foundRoutes);
2050
-
2051
1936
  if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
2052
1937
  recurse(foundRoute.childRoutes);
2053
1938
  }
2054
1939
  };
2055
-
2056
1940
  recurse([router.routeTree]);
2057
1941
  cascadeLoaderData(matches);
2058
1942
  return matches;
@@ -2061,14 +1945,11 @@
2061
1945
  const matchPromises = resolvedMatches.map(async match => {
2062
1946
  // Validate the match (loads search params etc)
2063
1947
  match.__.validate();
2064
-
2065
1948
  match.load(loaderOpts);
2066
1949
  const search = match.search;
2067
-
2068
1950
  if (search.__data && search.__data.matchId !== match.matchId) {
2069
1951
  return;
2070
1952
  }
2071
-
2072
1953
  if (match.__.loadPromise) {
2073
1954
  // Wait for the first sign of activity from the match
2074
1955
  await match.__.loadPromise;
@@ -2080,7 +1961,6 @@
2080
1961
  loadMatchData: async routeMatch => {
2081
1962
  if (isServer || !router.options.useServerData) {
2082
1963
  var _await$routeMatch$opt;
2083
-
2084
1964
  return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2085
1965
  // parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
2086
1966
  params: routeMatch.params,
@@ -2096,21 +1976,30 @@
2096
1976
  }
2097
1977
  })
2098
1978
  });
2099
- const res = await fetch(next.href, {
2100
- method: 'GET' // signal: routeMatch.__.abortController.signal,
2101
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,
2102
1993
  });
2103
1994
 
2104
1995
  if (res.ok) {
2105
1996
  return res.json();
2106
1997
  }
2107
-
2108
1998
  throw new Error('Failed to fetch match data');
2109
1999
  }
2110
2000
  },
2111
2001
  invalidateRoute: opts => {
2112
2002
  var _router$state$pending5, _router$state$pending6;
2113
-
2114
2003
  const next = router.buildNext(opts);
2115
2004
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
2116
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 => {
@@ -2129,25 +2018,21 @@
2129
2018
  },
2130
2019
  matchRoute: (location, opts) => {
2131
2020
  var _location$from;
2132
-
2133
2021
  // const location = router.buildNext(opts)
2022
+
2134
2023
  location = _extends({}, location, {
2135
2024
  to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
2136
2025
  });
2137
2026
  const next = router.buildNext(location);
2138
-
2139
2027
  if (opts != null && opts.pending) {
2140
2028
  var _router$state$pending7;
2141
-
2142
2029
  if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
2143
2030
  return false;
2144
2031
  }
2145
-
2146
2032
  return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
2147
2033
  to: next.pathname
2148
2034
  }));
2149
2035
  }
2150
-
2151
2036
  return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
2152
2037
  to: next.pathname
2153
2038
  }));
@@ -2163,17 +2048,16 @@
2163
2048
  } = _ref7;
2164
2049
  // If this link simply reloads the current route,
2165
2050
  // make sure it has a new key so it will trigger a data refresh
2051
+
2166
2052
  // If this `to` is a valid external URL, return
2167
2053
  // null for LinkUtils
2168
2054
  const toString = String(to);
2169
2055
  const fromString = String(from);
2170
2056
  let isExternal;
2171
-
2172
2057
  try {
2173
2058
  new URL("" + toString);
2174
2059
  isExternal = true;
2175
2060
  } catch (e) {}
2176
-
2177
2061
  invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
2178
2062
  return router.__.navigate({
2179
2063
  from: fromString,
@@ -2186,7 +2070,6 @@
2186
2070
  },
2187
2071
  buildLink: _ref8 => {
2188
2072
  var _preload, _ref9;
2189
-
2190
2073
  let {
2191
2074
  from,
2192
2075
  to = '.',
@@ -2202,11 +2085,12 @@
2202
2085
  preloadDelay: userPreloadDelay,
2203
2086
  disabled
2204
2087
  } = _ref8;
2205
-
2206
2088
  // If this link simply reloads the current route,
2207
2089
  // make sure it has a new key so it will trigger a data refresh
2090
+
2208
2091
  // If this `to` is a valid external URL, return
2209
2092
  // null for LinkUtils
2093
+
2210
2094
  try {
2211
2095
  new URL("" + to);
2212
2096
  return {
@@ -2214,7 +2098,6 @@
2214
2098
  href: to
2215
2099
  };
2216
2100
  } catch (e) {}
2217
-
2218
2101
  const nextOpts = {
2219
2102
  from,
2220
2103
  to,
@@ -2225,33 +2108,35 @@
2225
2108
  };
2226
2109
  const next = router.buildNext(nextOpts);
2227
2110
  preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2228
- const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
2111
+ const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
2229
2112
 
2113
+ // Compare path/hash for matches
2230
2114
  const pathIsEqual = router.state.location.pathname === next.pathname;
2231
2115
  const currentPathSplit = router.state.location.pathname.split('/');
2232
2116
  const nextPathSplit = next.pathname.split('/');
2233
2117
  const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
2234
- const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
2235
-
2118
+ const hashIsEqual = router.state.location.hash === next.hash;
2119
+ // Combine the matches based on user options
2236
2120
  const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
2237
- const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
2121
+ const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
2238
2122
 
2239
- const isActive = pathTest && hashTest; // The click handler
2123
+ // The final "active" test
2124
+ const isActive = pathTest && hashTest;
2240
2125
 
2126
+ // The click handler
2241
2127
  const handleClick = e => {
2242
2128
  if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
2243
2129
  e.preventDefault();
2244
-
2245
2130
  if (pathIsEqual && !search && !hash) {
2246
2131
  router.invalidateRoute(nextOpts);
2247
- } // All is well? Navigate!)
2248
-
2132
+ }
2249
2133
 
2134
+ // All is well? Navigate!)
2250
2135
  router.__.navigate(nextOpts);
2251
2136
  }
2252
- }; // The click handler
2253
-
2137
+ };
2254
2138
 
2139
+ // The click handler
2255
2140
  const handleFocus = e => {
2256
2141
  if (preload) {
2257
2142
  router.preloadRoute(nextOpts, {
@@ -2260,15 +2145,12 @@
2260
2145
  });
2261
2146
  }
2262
2147
  };
2263
-
2264
2148
  const handleEnter = e => {
2265
2149
  const target = e.target || {};
2266
-
2267
2150
  if (preload) {
2268
2151
  if (target.preloadTimeout) {
2269
2152
  return;
2270
2153
  }
2271
-
2272
2154
  target.preloadTimeout = setTimeout(() => {
2273
2155
  target.preloadTimeout = null;
2274
2156
  router.preloadRoute(nextOpts, {
@@ -2278,16 +2160,13 @@
2278
2160
  }, preloadDelay);
2279
2161
  }
2280
2162
  };
2281
-
2282
2163
  const handleLeave = e => {
2283
2164
  const target = e.target || {};
2284
-
2285
2165
  if (target.preloadTimeout) {
2286
2166
  clearTimeout(target.preloadTimeout);
2287
2167
  target.preloadTimeout = null;
2288
2168
  }
2289
2169
  };
2290
-
2291
2170
  return {
2292
2171
  type: 'internal',
2293
2172
  next,
@@ -2301,21 +2180,15 @@
2301
2180
  },
2302
2181
  buildNext: opts => {
2303
2182
  const next = router.__.buildLocation(opts);
2304
-
2305
2183
  const matches = router.matchRoutes(next.pathname);
2306
-
2307
2184
  const __preSearchFilters = matches.map(match => {
2308
2185
  var _match$options$preSea;
2309
-
2310
2186
  return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
2311
2187
  }).flat().filter(Boolean);
2312
-
2313
2188
  const __postSearchFilters = matches.map(match => {
2314
2189
  var _match$options$postSe;
2315
-
2316
2190
  return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
2317
2191
  }).flat().filter(Boolean);
2318
-
2319
2192
  return router.__.buildLocation(_extends({}, opts, {
2320
2193
  __preSearchFilters,
2321
2194
  __postSearchFilters
@@ -2328,12 +2201,10 @@
2328
2201
  const routeOptions = routeConfig.options;
2329
2202
  const route = createRoute(routeConfig, routeOptions, parent, router);
2330
2203
  const existingRoute = router.routesById[route.routeId];
2331
-
2332
2204
  if (existingRoute) {
2333
2205
  {
2334
2206
  console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
2335
2207
  }
2336
-
2337
2208
  throw new Error();
2338
2209
  }
2339
2210
  router.routesById[route.routeId] = route;
@@ -2342,13 +2213,11 @@
2342
2213
  return route;
2343
2214
  });
2344
2215
  };
2345
-
2346
2216
  const routes = recurseRoutes([rootRouteConfig]);
2347
2217
  return routes[0];
2348
2218
  },
2349
2219
  parseLocation: (location, previousLocation) => {
2350
2220
  var _location$hash$split$;
2351
-
2352
2221
  const parsedSearch = router.options.parseSearch(location.search);
2353
2222
  return {
2354
2223
  pathname: location.pathname,
@@ -2366,41 +2235,36 @@
2366
2235
  },
2367
2236
  buildLocation: function buildLocation(dest) {
2368
2237
  var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
2369
-
2370
2238
  if (dest === void 0) {
2371
2239
  dest = {};
2372
2240
  }
2373
-
2374
2241
  // const resolvedFrom: Location = {
2375
2242
  // ...router.location,
2376
2243
  const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
2377
-
2378
2244
  let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
2379
-
2380
2245
  const fromMatches = router.matchRoutes(router.location.pathname, {
2381
2246
  strictParseParams: true
2382
2247
  });
2383
2248
  const toMatches = router.matchRoutes(pathname);
2384
-
2385
2249
  const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
2386
-
2387
2250
  let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2388
-
2389
2251
  if (nextParams) {
2390
2252
  toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2391
2253
  Object.assign({}, nextParams, fn(nextParams));
2392
2254
  });
2393
2255
  }
2256
+ pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
2394
2257
 
2395
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
2396
-
2397
- 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;
2398
2260
 
2261
+ // Then the link/navigate function
2399
2262
  const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2400
2263
  : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
2401
2264
  : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2402
- : {}; // Then post filters
2265
+ : {};
2403
2266
 
2267
+ // Then post filters
2404
2268
  const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2405
2269
  const search = replaceEqualDeep(router.location.search, postFilteredSearch);
2406
2270
  const searchStr = router.options.stringifySearch(search);
@@ -2420,17 +2284,13 @@
2420
2284
  const id = '' + Date.now() + Math.random();
2421
2285
  if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
2422
2286
  let nextAction = 'replace';
2423
-
2424
2287
  if (!replace) {
2425
2288
  nextAction = 'push';
2426
2289
  }
2427
-
2428
2290
  const isSameUrl = router.__.parseLocation(history.location).href === next.href;
2429
-
2430
2291
  if (isSameUrl && !next.key) {
2431
2292
  nextAction = 'replace';
2432
2293
  }
2433
-
2434
2294
  if (nextAction === 'replace') {
2435
2295
  history.replace({
2436
2296
  pathname: next.pathname,
@@ -2448,33 +2308,30 @@
2448
2308
  id
2449
2309
  });
2450
2310
  }
2451
-
2452
2311
  router.navigationPromise = new Promise(resolve => {
2453
2312
  const previousNavigationResolve = router.resolveNavigation;
2454
-
2455
2313
  router.resolveNavigation = () => {
2456
2314
  previousNavigationResolve();
2457
2315
  resolve();
2316
+ delete router.navigationPromise;
2458
2317
  };
2459
2318
  });
2460
2319
  return router.navigationPromise;
2461
2320
  }
2462
2321
  }
2463
2322
  };
2464
- router.update(userOptions); // Allow frameworks to hook into the router creation
2323
+ router.update(userOptions);
2465
2324
 
2325
+ // Allow frameworks to hook into the router creation
2466
2326
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
2467
2327
  return router;
2468
2328
  }
2469
-
2470
2329
  function isCtrlEvent(e) {
2471
2330
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2472
2331
  }
2473
-
2474
2332
  function cascadeLoaderData(matches) {
2475
2333
  matches.forEach((match, index) => {
2476
2334
  const parent = matches[index - 1];
2477
-
2478
2335
  if (parent) {
2479
2336
  match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
2480
2337
  }