@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/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.253",
4
+ "version": "0.0.1-beta.255",
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.253"
47
+ "@tanstack/history": "0.0.1-beta.255"
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
@@ -710,11 +710,14 @@ export class Router<
710
710
  matches?: AnyRouteMatch[],
711
711
  ): ParsedLocation => {
712
712
  const from = this.latestLocation
713
+ const fromSearch =
714
+ (this.state.pendingMatches || this.state.matches).at(-1)?.search ||
715
+ from.search
713
716
  const fromPathname = dest.from ?? from.pathname
714
717
 
715
718
  let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`)
716
719
 
717
- const fromMatches = this.matchRoutes(fromPathname, from.search)
720
+ const fromMatches = this.matchRoutes(fromPathname, fromSearch)
718
721
  const stayingMatches = matches?.filter(
719
722
  (d) => fromMatches?.find((e) => e.routeId === d.routeId),
720
723
  )
@@ -761,9 +764,9 @@ export class Router<
761
764
  const preFilteredSearch = preSearchFilters?.length
762
765
  ? preSearchFilters?.reduce(
763
766
  (prev, next) => next(prev) as any,
764
- from.search,
767
+ fromSearch,
765
768
  )
766
- : from.search
769
+ : fromSearch
767
770
 
768
771
  // Then the link/navigate function
769
772
  const destSearch =
@@ -780,7 +783,7 @@ export class Router<
780
783
  ? postSearchFilters.reduce((prev, next) => next(prev), destSearch)
781
784
  : destSearch
782
785
 
783
- const search = replaceEqualDeep(from.search, postFilteredSearch)
786
+ const search = replaceEqualDeep(fromSearch, postFilteredSearch)
784
787
 
785
788
  const searchStr = this.options.stringifySearch(search)
786
789
 
@@ -1006,7 +1009,7 @@ export class Router<
1006
1009
  const parentMatch = matches[index - 1]
1007
1010
  const route = this.looseRoutesById[match.routeId]!
1008
1011
 
1009
- const handleError = (err: any, code: string) => {
1012
+ const handleErrorAndRedirect = (err: any, code: string) => {
1010
1013
  err.routerCode = code
1011
1014
  firstBadMatchIndex = firstBadMatchIndex ?? index
1012
1015
 
@@ -1034,11 +1037,11 @@ export class Router<
1034
1037
 
1035
1038
  try {
1036
1039
  if (match.paramsError) {
1037
- handleError(match.paramsError, 'PARSE_PARAMS')
1040
+ handleErrorAndRedirect(match.paramsError, 'PARSE_PARAMS')
1038
1041
  }
1039
1042
 
1040
1043
  if (match.searchError) {
1041
- handleError(match.searchError, 'VALIDATE_SEARCH')
1044
+ handleErrorAndRedirect(match.searchError, 'VALIDATE_SEARCH')
1042
1045
  }
1043
1046
 
1044
1047
  const parentContext =
@@ -1059,6 +1062,10 @@ export class Router<
1059
1062
  cause: match.cause,
1060
1063
  })) ?? ({} as any)
1061
1064
 
1065
+ if (isRedirect(beforeLoadContext)) {
1066
+ throw beforeLoadContext
1067
+ }
1068
+
1062
1069
  const context = {
1063
1070
  ...parentContext,
1064
1071
  ...beforeLoadContext,
@@ -1069,7 +1076,7 @@ export class Router<
1069
1076
  context: replaceEqualDeep(match.context, context),
1070
1077
  }
1071
1078
  } catch (err) {
1072
- handleError(err, 'BEFORE_LOAD')
1079
+ handleErrorAndRedirect(err, 'BEFORE_LOAD')
1073
1080
  break
1074
1081
  }
1075
1082
  }
@@ -1091,7 +1098,7 @@ export class Router<
1091
1098
  const parentMatchPromise = matchPromises[index - 1]
1092
1099
  const route = this.looseRoutesById[match.routeId]!
1093
1100
 
1094
- const handleIfRedirect = (err: any) => {
1101
+ const handleErrorAndRedirect = (err: any) => {
1095
1102
  if (isRedirect(err)) {
1096
1103
  if (!preload) {
1097
1104
  this.navigate(err as any)
@@ -1230,6 +1237,10 @@ export class Router<
1230
1237
  const loaderData = await loadPromise
1231
1238
  if ((latestPromise = checkLatest())) return await latestPromise
1232
1239
 
1240
+ if (isRedirect(loaderData)) {
1241
+ if (handleErrorAndRedirect(loaderData)) return
1242
+ }
1243
+
1233
1244
  if (didShowPending && pendingMinMs) {
1234
1245
  await new Promise((r) => setTimeout(r, pendingMinMs))
1235
1246
  }
@@ -1247,13 +1258,13 @@ export class Router<
1247
1258
  }
1248
1259
  } catch (error) {
1249
1260
  if ((latestPromise = checkLatest())) return await latestPromise
1250
- if (handleIfRedirect(error)) return
1261
+ if (handleErrorAndRedirect(error)) return
1251
1262
 
1252
1263
  try {
1253
1264
  route.options.onError?.(error)
1254
1265
  } catch (onErrorError) {
1255
1266
  error = onErrorError
1256
- if (handleIfRedirect(onErrorError)) return
1267
+ if (handleErrorAndRedirect(onErrorError)) return
1257
1268
  }
1258
1269
 
1259
1270
  matches[index] = match = {