@tanstack/react-router 0.0.1-beta.253 → 0.0.1-beta.255
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/router.js +17 -10
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +17 -10
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/umd/index.development.js +17 -10
- 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/routeInfo.ts +6 -6
- package/src/router.ts +22 -11
|
@@ -2224,9 +2224,10 @@
|
|
|
2224
2224
|
buildLocation = opts => {
|
|
2225
2225
|
const build = (dest = {}, matches) => {
|
|
2226
2226
|
const from = this.latestLocation;
|
|
2227
|
+
const fromSearch = (this.state.pendingMatches || this.state.matches).at(-1)?.search || from.search;
|
|
2227
2228
|
const fromPathname = dest.from ?? from.pathname;
|
|
2228
2229
|
let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`);
|
|
2229
|
-
const fromMatches = this.matchRoutes(fromPathname,
|
|
2230
|
+
const fromMatches = this.matchRoutes(fromPathname, fromSearch);
|
|
2230
2231
|
const stayingMatches = matches?.filter(d => fromMatches?.find(e => e.routeId === d.routeId));
|
|
2231
2232
|
const prevParams = {
|
|
2232
2233
|
...last(fromMatches)?.params
|
|
@@ -2245,7 +2246,7 @@
|
|
|
2245
2246
|
const postSearchFilters = stayingMatches?.map(match => this.looseRoutesById[match.routeId].options.postSearchFilters ?? []).flat().filter(Boolean) ?? [];
|
|
2246
2247
|
|
|
2247
2248
|
// Pre filters first
|
|
2248
|
-
const preFilteredSearch = preSearchFilters?.length ? preSearchFilters?.reduce((prev, next) => next(prev),
|
|
2249
|
+
const preFilteredSearch = preSearchFilters?.length ? preSearchFilters?.reduce((prev, next) => next(prev), fromSearch) : fromSearch;
|
|
2249
2250
|
|
|
2250
2251
|
// Then the link/navigate function
|
|
2251
2252
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
@@ -2255,7 +2256,7 @@
|
|
|
2255
2256
|
|
|
2256
2257
|
// Then post filters
|
|
2257
2258
|
const postFilteredSearch = postSearchFilters?.length ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2258
|
-
const search = replaceEqualDeep(
|
|
2259
|
+
const search = replaceEqualDeep(fromSearch, postFilteredSearch);
|
|
2259
2260
|
const searchStr = this.options.stringifySearch(search);
|
|
2260
2261
|
const hash = dest.hash === true ? from.hash : dest.hash ? functionalUpdate(dest.hash, from.hash) : from.hash;
|
|
2261
2262
|
const hashStr = hash ? `#${hash}` : '';
|
|
@@ -2420,7 +2421,7 @@
|
|
|
2420
2421
|
for (let [index, match] of matches.entries()) {
|
|
2421
2422
|
const parentMatch = matches[index - 1];
|
|
2422
2423
|
const route = this.looseRoutesById[match.routeId];
|
|
2423
|
-
const
|
|
2424
|
+
const handleErrorAndRedirect = (err, code) => {
|
|
2424
2425
|
err.routerCode = code;
|
|
2425
2426
|
firstBadMatchIndex = firstBadMatchIndex ?? index;
|
|
2426
2427
|
if (isRedirect(err)) {
|
|
@@ -2443,10 +2444,10 @@
|
|
|
2443
2444
|
};
|
|
2444
2445
|
try {
|
|
2445
2446
|
if (match.paramsError) {
|
|
2446
|
-
|
|
2447
|
+
handleErrorAndRedirect(match.paramsError, 'PARSE_PARAMS');
|
|
2447
2448
|
}
|
|
2448
2449
|
if (match.searchError) {
|
|
2449
|
-
|
|
2450
|
+
handleErrorAndRedirect(match.searchError, 'VALIDATE_SEARCH');
|
|
2450
2451
|
}
|
|
2451
2452
|
const parentContext = parentMatch?.context ?? this.options.context ?? {};
|
|
2452
2453
|
const beforeLoadContext = (await route.options.beforeLoad?.({
|
|
@@ -2464,6 +2465,9 @@
|
|
|
2464
2465
|
buildLocation: this.buildLocation,
|
|
2465
2466
|
cause: match.cause
|
|
2466
2467
|
})) ?? {};
|
|
2468
|
+
if (isRedirect(beforeLoadContext)) {
|
|
2469
|
+
throw beforeLoadContext;
|
|
2470
|
+
}
|
|
2467
2471
|
const context = {
|
|
2468
2472
|
...parentContext,
|
|
2469
2473
|
...beforeLoadContext
|
|
@@ -2473,7 +2477,7 @@
|
|
|
2473
2477
|
context: replaceEqualDeep(match.context, context)
|
|
2474
2478
|
};
|
|
2475
2479
|
} catch (err) {
|
|
2476
|
-
|
|
2480
|
+
handleErrorAndRedirect(err, 'BEFORE_LOAD');
|
|
2477
2481
|
break;
|
|
2478
2482
|
}
|
|
2479
2483
|
}
|
|
@@ -2490,7 +2494,7 @@
|
|
|
2490
2494
|
matchPromises.push((async () => {
|
|
2491
2495
|
const parentMatchPromise = matchPromises[index - 1];
|
|
2492
2496
|
const route = this.looseRoutesById[match.routeId];
|
|
2493
|
-
const
|
|
2497
|
+
const handleErrorAndRedirect = err => {
|
|
2494
2498
|
if (isRedirect(err)) {
|
|
2495
2499
|
if (!preload) {
|
|
2496
2500
|
this.navigate(err);
|
|
@@ -2592,6 +2596,9 @@
|
|
|
2592
2596
|
try {
|
|
2593
2597
|
const loaderData = await loadPromise;
|
|
2594
2598
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
2599
|
+
if (isRedirect(loaderData)) {
|
|
2600
|
+
if (handleErrorAndRedirect(loaderData)) return;
|
|
2601
|
+
}
|
|
2595
2602
|
if (didShowPending && pendingMinMs) {
|
|
2596
2603
|
await new Promise(r => setTimeout(r, pendingMinMs));
|
|
2597
2604
|
}
|
|
@@ -2607,12 +2614,12 @@
|
|
|
2607
2614
|
};
|
|
2608
2615
|
} catch (error) {
|
|
2609
2616
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
2610
|
-
if (
|
|
2617
|
+
if (handleErrorAndRedirect(error)) return;
|
|
2611
2618
|
try {
|
|
2612
2619
|
route.options.onError?.(error);
|
|
2613
2620
|
} catch (onErrorError) {
|
|
2614
2621
|
error = onErrorError;
|
|
2615
|
-
if (
|
|
2622
|
+
if (handleErrorAndRedirect(onErrorError)) return;
|
|
2616
2623
|
}
|
|
2617
2624
|
matches[index] = match = {
|
|
2618
2625
|
...match,
|