@tanstack/router-core 0.0.1-beta.192 → 0.0.1-beta.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +29 -18
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +29 -18
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +124 -124
- package/build/types/fileRoute.d.ts +4 -4
- package/build/types/link.d.ts +9 -9
- package/build/types/route.d.ts +72 -62
- package/build/types/routeInfo.d.ts +4 -4
- package/build/types/router.d.ts +1 -2
- package/build/types/utils.d.ts +8 -1
- package/build/umd/index.development.js +29 -18
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +12 -10
- package/src/link.ts +27 -14
- package/src/route.ts +155 -197
- package/src/routeInfo.ts +10 -7
- package/src/router.ts +51 -25
- package/src/utils.ts +21 -1
package/build/esm/index.js
CHANGED
|
@@ -1086,12 +1086,19 @@ class Router {
|
|
|
1086
1086
|
});
|
|
1087
1087
|
const matches = matchedRoutes.map((route, index) => {
|
|
1088
1088
|
const interpolatedPath = interpolatePath(route.path, routeParams);
|
|
1089
|
-
const
|
|
1090
|
-
params: routeParams,
|
|
1089
|
+
const loaderContext = route.options.loaderContext ? route.options.loaderContext({
|
|
1091
1090
|
search: locationSearch
|
|
1092
|
-
})
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1091
|
+
}) : undefined;
|
|
1092
|
+
const matchId = JSON.stringify([interpolatePath(route.id, routeParams, true), loaderContext].filter(d => d !== undefined), (key, value) => {
|
|
1093
|
+
if (typeof value === 'function') {
|
|
1094
|
+
console.info(route);
|
|
1095
|
+
invariant(false, `Cannot return functions and other non-serializable values from routeOptions.loaderContext! Please use routeOptions.beforeLoad to do this. Route info is logged above 👆`);
|
|
1096
|
+
}
|
|
1097
|
+
if (typeof value === 'object' && value !== null) {
|
|
1098
|
+
return Object.fromEntries(Object.keys(value).sort().map(key => [key, value[key]]));
|
|
1099
|
+
}
|
|
1100
|
+
return value;
|
|
1101
|
+
});
|
|
1095
1102
|
|
|
1096
1103
|
// Waste not, want not. If we already have a match for this route,
|
|
1097
1104
|
// reuse it. This is important for layout routes, which might stick
|
|
@@ -1107,7 +1114,7 @@ class Router {
|
|
|
1107
1114
|
const hasLoaders = !!(route.options.loader || componentTypes.some(d => route.options[d]?.preload));
|
|
1108
1115
|
const routeMatch = {
|
|
1109
1116
|
id: matchId,
|
|
1110
|
-
|
|
1117
|
+
loaderContext,
|
|
1111
1118
|
routeId: route.id,
|
|
1112
1119
|
params: routeParams,
|
|
1113
1120
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
@@ -1124,7 +1131,6 @@ class Router {
|
|
|
1124
1131
|
searchError: undefined,
|
|
1125
1132
|
loaderData: undefined,
|
|
1126
1133
|
loadPromise: Promise.resolve(),
|
|
1127
|
-
routeContext: undefined,
|
|
1128
1134
|
context: undefined,
|
|
1129
1135
|
abortController: new AbortController(),
|
|
1130
1136
|
fetchedAt: 0
|
|
@@ -1181,7 +1187,6 @@ class Router {
|
|
|
1181
1187
|
...s,
|
|
1182
1188
|
routeSearch: match.routeSearch,
|
|
1183
1189
|
search: match.search,
|
|
1184
|
-
routeContext: match.routeContext,
|
|
1185
1190
|
context: match.context,
|
|
1186
1191
|
error: match.error,
|
|
1187
1192
|
paramsError: match.paramsError,
|
|
@@ -1226,21 +1231,25 @@ class Router {
|
|
|
1226
1231
|
handleError(match.searchError, 'VALIDATE_SEARCH');
|
|
1227
1232
|
}
|
|
1228
1233
|
let didError = false;
|
|
1234
|
+
const parentContext = parentMatch?.context ?? this?.options.context ?? {};
|
|
1229
1235
|
try {
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1236
|
+
const beforeLoadContext = (await route.options.beforeLoad?.({
|
|
1237
|
+
abortController: match.abortController,
|
|
1238
|
+
params: match.params,
|
|
1232
1239
|
preload: !!opts?.preload,
|
|
1233
|
-
|
|
1234
|
-
|
|
1240
|
+
context: {
|
|
1241
|
+
...parentContext,
|
|
1242
|
+
...match.loaderContext
|
|
1243
|
+
}
|
|
1235
1244
|
})) ?? {};
|
|
1236
1245
|
const context = {
|
|
1237
|
-
...
|
|
1238
|
-
...
|
|
1246
|
+
...parentContext,
|
|
1247
|
+
...match.loaderContext,
|
|
1248
|
+
...beforeLoadContext
|
|
1239
1249
|
};
|
|
1240
1250
|
this.setRouteMatch(match.id, s => ({
|
|
1241
1251
|
...s,
|
|
1242
|
-
context,
|
|
1243
|
-
routeContext
|
|
1252
|
+
context: replaceEqualDeep(s.context, context)
|
|
1244
1253
|
}));
|
|
1245
1254
|
} catch (err) {
|
|
1246
1255
|
handleError(err, 'BEFORE_LOAD');
|
|
@@ -1294,9 +1303,11 @@ class Router {
|
|
|
1294
1303
|
}
|
|
1295
1304
|
}));
|
|
1296
1305
|
const loaderPromise = route.options.loader?.({
|
|
1297
|
-
|
|
1306
|
+
params: match.params,
|
|
1298
1307
|
preload: !!opts?.preload,
|
|
1299
|
-
parentMatchPromise
|
|
1308
|
+
parentMatchPromise,
|
|
1309
|
+
abortController: match.abortController,
|
|
1310
|
+
context: match.context
|
|
1300
1311
|
});
|
|
1301
1312
|
const [_, loader] = await Promise.all([componentsPromise, loaderPromise]);
|
|
1302
1313
|
if (latestPromise = checkLatest()) return await latestPromise;
|