@tanstack/react-router 0.0.1-beta.253 → 0.0.1-beta.254

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.
@@ -2420,7 +2420,7 @@
2420
2420
  for (let [index, match] of matches.entries()) {
2421
2421
  const parentMatch = matches[index - 1];
2422
2422
  const route = this.looseRoutesById[match.routeId];
2423
- const handleError = (err, code) => {
2423
+ const handleErrorAndRedirect = (err, code) => {
2424
2424
  err.routerCode = code;
2425
2425
  firstBadMatchIndex = firstBadMatchIndex ?? index;
2426
2426
  if (isRedirect(err)) {
@@ -2443,10 +2443,10 @@
2443
2443
  };
2444
2444
  try {
2445
2445
  if (match.paramsError) {
2446
- handleError(match.paramsError, 'PARSE_PARAMS');
2446
+ handleErrorAndRedirect(match.paramsError, 'PARSE_PARAMS');
2447
2447
  }
2448
2448
  if (match.searchError) {
2449
- handleError(match.searchError, 'VALIDATE_SEARCH');
2449
+ handleErrorAndRedirect(match.searchError, 'VALIDATE_SEARCH');
2450
2450
  }
2451
2451
  const parentContext = parentMatch?.context ?? this.options.context ?? {};
2452
2452
  const beforeLoadContext = (await route.options.beforeLoad?.({
@@ -2464,6 +2464,9 @@
2464
2464
  buildLocation: this.buildLocation,
2465
2465
  cause: match.cause
2466
2466
  })) ?? {};
2467
+ if (isRedirect(beforeLoadContext)) {
2468
+ throw beforeLoadContext;
2469
+ }
2467
2470
  const context = {
2468
2471
  ...parentContext,
2469
2472
  ...beforeLoadContext
@@ -2473,7 +2476,7 @@
2473
2476
  context: replaceEqualDeep(match.context, context)
2474
2477
  };
2475
2478
  } catch (err) {
2476
- handleError(err, 'BEFORE_LOAD');
2479
+ handleErrorAndRedirect(err, 'BEFORE_LOAD');
2477
2480
  break;
2478
2481
  }
2479
2482
  }
@@ -2490,7 +2493,7 @@
2490
2493
  matchPromises.push((async () => {
2491
2494
  const parentMatchPromise = matchPromises[index - 1];
2492
2495
  const route = this.looseRoutesById[match.routeId];
2493
- const handleIfRedirect = err => {
2496
+ const handleErrorAndRedirect = err => {
2494
2497
  if (isRedirect(err)) {
2495
2498
  if (!preload) {
2496
2499
  this.navigate(err);
@@ -2592,6 +2595,9 @@
2592
2595
  try {
2593
2596
  const loaderData = await loadPromise;
2594
2597
  if (latestPromise = checkLatest()) return await latestPromise;
2598
+ if (isRedirect(loaderData)) {
2599
+ if (handleErrorAndRedirect(loaderData)) return;
2600
+ }
2595
2601
  if (didShowPending && pendingMinMs) {
2596
2602
  await new Promise(r => setTimeout(r, pendingMinMs));
2597
2603
  }
@@ -2607,12 +2613,12 @@
2607
2613
  };
2608
2614
  } catch (error) {
2609
2615
  if (latestPromise = checkLatest()) return await latestPromise;
2610
- if (handleIfRedirect(error)) return;
2616
+ if (handleErrorAndRedirect(error)) return;
2611
2617
  try {
2612
2618
  route.options.onError?.(error);
2613
2619
  } catch (onErrorError) {
2614
2620
  error = onErrorError;
2615
- if (handleIfRedirect(onErrorError)) return;
2621
+ if (handleErrorAndRedirect(onErrorError)) return;
2616
2622
  }
2617
2623
  matches[index] = match = {
2618
2624
  ...match,