@tanstack/react-router 0.0.1-beta.176 → 0.0.1-beta.178
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/react.js +11 -11
- package/build/cjs/react.js.map +1 -1
- package/build/esm/index.js +11 -11
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +98 -98
- package/build/types/react.d.ts +12 -18
- package/build/umd/index.development.js +38 -54
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/react.tsx +28 -40
|
@@ -964,7 +964,7 @@
|
|
|
964
964
|
};
|
|
965
965
|
#onFocus = () => {
|
|
966
966
|
if (this.options.refetchOnWindowFocus ?? true) {
|
|
967
|
-
this.
|
|
967
|
+
this.invalidate();
|
|
968
968
|
}
|
|
969
969
|
};
|
|
970
970
|
update = opts => {
|
|
@@ -1300,39 +1300,14 @@
|
|
|
1300
1300
|
return parentSearchInfo;
|
|
1301
1301
|
}
|
|
1302
1302
|
})();
|
|
1303
|
-
Object.assign(match,
|
|
1304
|
-
...searchInfo
|
|
1305
|
-
});
|
|
1306
|
-
const contextInfo = (() => {
|
|
1307
|
-
try {
|
|
1308
|
-
const routeContext = route.options.getContext?.({
|
|
1309
|
-
parentContext: parentMatch?.routeContext ?? {},
|
|
1310
|
-
context: parentMatch?.context ?? this?.options.context ?? {},
|
|
1311
|
-
params: match.params,
|
|
1312
|
-
search: match.search
|
|
1313
|
-
}) || {};
|
|
1314
|
-
const context = {
|
|
1315
|
-
...(parentMatch?.context ?? this?.options.context),
|
|
1316
|
-
...routeContext
|
|
1317
|
-
};
|
|
1318
|
-
return {
|
|
1319
|
-
context,
|
|
1320
|
-
routeContext
|
|
1321
|
-
};
|
|
1322
|
-
} catch (err) {
|
|
1323
|
-
route.options.onError?.(err);
|
|
1324
|
-
throw err;
|
|
1325
|
-
}
|
|
1326
|
-
})();
|
|
1327
|
-
Object.assign(match, {
|
|
1328
|
-
...contextInfo
|
|
1329
|
-
});
|
|
1303
|
+
Object.assign(match, searchInfo);
|
|
1330
1304
|
});
|
|
1331
1305
|
return matches;
|
|
1332
1306
|
};
|
|
1333
|
-
loadMatches = async (
|
|
1307
|
+
loadMatches = async (_resolvedMatches, opts) => {
|
|
1308
|
+
const getFreshMatches = () => _resolvedMatches.map(d => this.getRouteMatch(d.id));
|
|
1334
1309
|
if (!opts?.preload) {
|
|
1335
|
-
|
|
1310
|
+
getFreshMatches().forEach(match => {
|
|
1336
1311
|
// Update each match with its latest route data
|
|
1337
1312
|
this.setRouteMatch(match.id, s => ({
|
|
1338
1313
|
...s,
|
|
@@ -1352,7 +1327,8 @@
|
|
|
1352
1327
|
|
|
1353
1328
|
// Check each match middleware to see if the route can be accessed
|
|
1354
1329
|
try {
|
|
1355
|
-
for (const [index, match] of
|
|
1330
|
+
for (const [index, match] of getFreshMatches().entries()) {
|
|
1331
|
+
const parentMatch = getFreshMatches()[index - 1];
|
|
1356
1332
|
const route = this.getRoute(match.routeId);
|
|
1357
1333
|
const handleError = (err, code) => {
|
|
1358
1334
|
err.routerCode = code;
|
|
@@ -1383,10 +1359,21 @@
|
|
|
1383
1359
|
}
|
|
1384
1360
|
let didError = false;
|
|
1385
1361
|
try {
|
|
1386
|
-
await route.options.beforeLoad?.({
|
|
1362
|
+
const routeContext = (await route.options.beforeLoad?.({
|
|
1387
1363
|
...match,
|
|
1388
|
-
preload: !!opts?.preload
|
|
1389
|
-
|
|
1364
|
+
preload: !!opts?.preload,
|
|
1365
|
+
parentContext: parentMatch?.routeContext ?? {},
|
|
1366
|
+
context: parentMatch?.context ?? this?.options.context ?? {}
|
|
1367
|
+
})) ?? {};
|
|
1368
|
+
const context = {
|
|
1369
|
+
...(parentMatch?.context ?? this?.options.context),
|
|
1370
|
+
...routeContext
|
|
1371
|
+
};
|
|
1372
|
+
this.setRouteMatch(match.id, s => ({
|
|
1373
|
+
...s,
|
|
1374
|
+
context,
|
|
1375
|
+
routeContext
|
|
1376
|
+
}));
|
|
1390
1377
|
} catch (err) {
|
|
1391
1378
|
handleError(err, 'BEFORE_LOAD');
|
|
1392
1379
|
didError = true;
|
|
@@ -1403,7 +1390,7 @@
|
|
|
1403
1390
|
}
|
|
1404
1391
|
throw err;
|
|
1405
1392
|
}
|
|
1406
|
-
const validResolvedMatches =
|
|
1393
|
+
const validResolvedMatches = getFreshMatches().slice(0, firstBadMatchIndex);
|
|
1407
1394
|
const matchPromises = [];
|
|
1408
1395
|
validResolvedMatches.forEach((match, index) => {
|
|
1409
1396
|
matchPromises.push((async () => {
|
|
@@ -1483,13 +1470,6 @@
|
|
|
1483
1470
|
});
|
|
1484
1471
|
await Promise.all(matchPromises);
|
|
1485
1472
|
};
|
|
1486
|
-
reload = () => {
|
|
1487
|
-
return this.navigate({
|
|
1488
|
-
fromCurrent: true,
|
|
1489
|
-
replace: true,
|
|
1490
|
-
search: true
|
|
1491
|
-
});
|
|
1492
|
-
};
|
|
1493
1473
|
resolvePath = (from, path) => {
|
|
1494
1474
|
return resolvePath(this.basepath, from, cleanPath(path));
|
|
1495
1475
|
};
|
|
@@ -1967,7 +1947,11 @@
|
|
|
1967
1947
|
});
|
|
1968
1948
|
}
|
|
1969
1949
|
if (opts?.reload ?? true) {
|
|
1970
|
-
return this.
|
|
1950
|
+
return this.navigate({
|
|
1951
|
+
fromCurrent: true,
|
|
1952
|
+
replace: true,
|
|
1953
|
+
search: true
|
|
1954
|
+
});
|
|
1971
1955
|
}
|
|
1972
1956
|
};
|
|
1973
1957
|
}
|
|
@@ -2203,14 +2187,14 @@
|
|
|
2203
2187
|
return useMatch({
|
|
2204
2188
|
...opts,
|
|
2205
2189
|
from: route.id,
|
|
2206
|
-
select: d => opts?.select
|
|
2190
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
2207
2191
|
});
|
|
2208
2192
|
},
|
|
2209
2193
|
useRouteContext: (opts = {}) => {
|
|
2210
2194
|
return useMatch({
|
|
2211
2195
|
...opts,
|
|
2212
2196
|
from: route.id,
|
|
2213
|
-
select: d => opts?.select
|
|
2197
|
+
select: d => opts?.select ? opts.select(d.routeContext) : d.routeContext
|
|
2214
2198
|
});
|
|
2215
2199
|
},
|
|
2216
2200
|
useSearch: (opts = {}) => {
|
|
@@ -2417,7 +2401,7 @@
|
|
|
2417
2401
|
return useRouterState({
|
|
2418
2402
|
select: state => {
|
|
2419
2403
|
const matches = state.matches.slice(state.matches.findIndex(d => d.id === matchIds[0]));
|
|
2420
|
-
return opts?.select
|
|
2404
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
2421
2405
|
}
|
|
2422
2406
|
});
|
|
2423
2407
|
}
|
|
@@ -2435,39 +2419,39 @@
|
|
|
2435
2419
|
if (opts?.strict ?? true) {
|
|
2436
2420
|
invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
|
|
2437
2421
|
}
|
|
2438
|
-
const
|
|
2422
|
+
const matchSelection = useRouterState({
|
|
2439
2423
|
select: state => {
|
|
2440
2424
|
const matches = state.matches;
|
|
2441
2425
|
const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatchId);
|
|
2442
2426
|
invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
|
|
2443
|
-
return opts?.select
|
|
2427
|
+
return opts?.select ? opts.select(match) : match;
|
|
2444
2428
|
}
|
|
2445
2429
|
});
|
|
2446
|
-
return
|
|
2430
|
+
return matchSelection;
|
|
2447
2431
|
}
|
|
2448
2432
|
function useLoader(opts) {
|
|
2449
2433
|
return useMatch({
|
|
2450
2434
|
...opts,
|
|
2451
|
-
select: match => opts?.select?.(match.loaderData)
|
|
2435
|
+
select: match => opts?.select ? opts?.select(match.loaderData) : match.loaderData
|
|
2452
2436
|
});
|
|
2453
2437
|
}
|
|
2454
2438
|
function useRouterContext(opts) {
|
|
2455
2439
|
return useMatch({
|
|
2456
2440
|
...opts,
|
|
2457
|
-
select: match => opts?.select
|
|
2441
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
2458
2442
|
});
|
|
2459
2443
|
}
|
|
2460
2444
|
function useRouteContext(opts) {
|
|
2461
2445
|
return useMatch({
|
|
2462
2446
|
...opts,
|
|
2463
|
-
select: match => opts?.select
|
|
2447
|
+
select: match => opts?.select ? opts.select(match.routeContext) : match.routeContext
|
|
2464
2448
|
});
|
|
2465
2449
|
}
|
|
2466
2450
|
function useSearch(opts) {
|
|
2467
2451
|
return useMatch({
|
|
2468
2452
|
...opts,
|
|
2469
2453
|
select: match => {
|
|
2470
|
-
return opts?.select
|
|
2454
|
+
return opts?.select ? opts.select(match.search) : match.search;
|
|
2471
2455
|
}
|
|
2472
2456
|
});
|
|
2473
2457
|
}
|
|
@@ -2475,7 +2459,7 @@
|
|
|
2475
2459
|
return useRouterState({
|
|
2476
2460
|
select: state => {
|
|
2477
2461
|
const params = last(state.matches)?.params;
|
|
2478
|
-
return opts?.select
|
|
2462
|
+
return opts?.select ? opts.select(params) : params;
|
|
2479
2463
|
}
|
|
2480
2464
|
});
|
|
2481
2465
|
}
|