@tanstack/react-router 0.0.1-beta.252 → 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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.252",
4
+ "version": "0.0.1-beta.254",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.252"
47
+ "@tanstack/history": "0.0.1-beta.254"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/routeInfo.ts CHANGED
@@ -25,12 +25,12 @@ export type ParseRouteChildren<TRouteTree extends AnyRoute> =
25
25
  ? unknown extends TChildren
26
26
  ? never
27
27
  : TChildren extends AnyRoute[]
28
- ? {
29
- [TId in TChildren[number]['id'] as string]: ParseRoute<
30
- TChildren[number]
31
- >
32
- }[string]
33
- : never
28
+ ? {
29
+ [TId in TChildren[number]['id'] as string]: ParseRoute<
30
+ TChildren[number]
31
+ >
32
+ }[string]
33
+ : never
34
34
  : never
35
35
 
36
36
  export type RoutesById<TRouteTree extends AnyRoute> = {
package/src/router.ts CHANGED
@@ -1006,7 +1006,7 @@ export class Router<
1006
1006
  const parentMatch = matches[index - 1]
1007
1007
  const route = this.looseRoutesById[match.routeId]!
1008
1008
 
1009
- const handleError = (err: any, code: string) => {
1009
+ const handleErrorAndRedirect = (err: any, code: string) => {
1010
1010
  err.routerCode = code
1011
1011
  firstBadMatchIndex = firstBadMatchIndex ?? index
1012
1012
 
@@ -1034,11 +1034,11 @@ export class Router<
1034
1034
 
1035
1035
  try {
1036
1036
  if (match.paramsError) {
1037
- handleError(match.paramsError, 'PARSE_PARAMS')
1037
+ handleErrorAndRedirect(match.paramsError, 'PARSE_PARAMS')
1038
1038
  }
1039
1039
 
1040
1040
  if (match.searchError) {
1041
- handleError(match.searchError, 'VALIDATE_SEARCH')
1041
+ handleErrorAndRedirect(match.searchError, 'VALIDATE_SEARCH')
1042
1042
  }
1043
1043
 
1044
1044
  const parentContext =
@@ -1059,6 +1059,10 @@ export class Router<
1059
1059
  cause: match.cause,
1060
1060
  })) ?? ({} as any)
1061
1061
 
1062
+ if (isRedirect(beforeLoadContext)) {
1063
+ throw beforeLoadContext
1064
+ }
1065
+
1062
1066
  const context = {
1063
1067
  ...parentContext,
1064
1068
  ...beforeLoadContext,
@@ -1069,7 +1073,7 @@ export class Router<
1069
1073
  context: replaceEqualDeep(match.context, context),
1070
1074
  }
1071
1075
  } catch (err) {
1072
- handleError(err, 'BEFORE_LOAD')
1076
+ handleErrorAndRedirect(err, 'BEFORE_LOAD')
1073
1077
  break
1074
1078
  }
1075
1079
  }
@@ -1091,7 +1095,7 @@ export class Router<
1091
1095
  const parentMatchPromise = matchPromises[index - 1]
1092
1096
  const route = this.looseRoutesById[match.routeId]!
1093
1097
 
1094
- const handleIfRedirect = (err: any) => {
1098
+ const handleErrorAndRedirect = (err: any) => {
1095
1099
  if (isRedirect(err)) {
1096
1100
  if (!preload) {
1097
1101
  this.navigate(err as any)
@@ -1230,6 +1234,10 @@ export class Router<
1230
1234
  const loaderData = await loadPromise
1231
1235
  if ((latestPromise = checkLatest())) return await latestPromise
1232
1236
 
1237
+ if (isRedirect(loaderData)) {
1238
+ if (handleErrorAndRedirect(loaderData)) return
1239
+ }
1240
+
1233
1241
  if (didShowPending && pendingMinMs) {
1234
1242
  await new Promise((r) => setTimeout(r, pendingMinMs))
1235
1243
  }
@@ -1247,13 +1255,13 @@ export class Router<
1247
1255
  }
1248
1256
  } catch (error) {
1249
1257
  if ((latestPromise = checkLatest())) return await latestPromise
1250
- if (handleIfRedirect(error)) return
1258
+ if (handleErrorAndRedirect(error)) return
1251
1259
 
1252
1260
  try {
1253
1261
  route.options.onError?.(error)
1254
1262
  } catch (onErrorError) {
1255
1263
  error = onErrorError
1256
- if (handleIfRedirect(onErrorError)) return
1264
+ if (handleErrorAndRedirect(onErrorError)) return
1257
1265
  }
1258
1266
 
1259
1267
  matches[index] = match = {