@tanstack/react-router 1.36.2 → 1.38.1

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/src/router.ts CHANGED
@@ -1558,7 +1558,7 @@ export class Router<
1558
1558
  redirect = err
1559
1559
  if (!this.isServer) {
1560
1560
  this.navigate({ ...err, replace: true, __isRedirect: true })
1561
- this.load()
1561
+ // this.load()
1562
1562
  }
1563
1563
  } else if (isNotFound(err)) {
1564
1564
  notFound = err
@@ -1677,7 +1677,7 @@ export class Router<
1677
1677
 
1678
1678
  if (isRedirect(err)) {
1679
1679
  rendered = true
1680
- err = this.resolveRedirect(err)
1680
+ err = this.resolveRedirect({ ...err, _fromLocation: location })
1681
1681
  throw err
1682
1682
  } else if (isNotFound(err)) {
1683
1683
  this.handleNotFound(matches, err)
@@ -1783,28 +1783,32 @@ export class Router<
1783
1783
  parentMatch?.context ?? this.options.context ?? {}
1784
1784
 
1785
1785
  // Make sure the match has parent context set before going further
1786
- matches[index] = match = updateMatch(match.id, () => ({
1786
+ matches[index] = match = {
1787
1787
  ...match,
1788
1788
  routeContext: replaceEqualDeep(
1789
1789
  match.routeContext,
1790
1790
  parentContext,
1791
1791
  ),
1792
+ context: replaceEqualDeep(match.context, parentContext),
1792
1793
  abortController,
1793
- }))
1794
+ }
1794
1795
 
1795
- const beforeLoadContext =
1796
- (await route.options.beforeLoad?.({
1797
- search: match.search,
1798
- abortController,
1799
- params: match.params,
1800
- preload: !!preload,
1801
- context: parentContext,
1802
- location,
1803
- navigate: (opts: any) =>
1804
- this.navigate({ ...opts, _fromLocation: location }),
1805
- buildLocation: this.buildLocation,
1806
- cause: preload ? 'preload' : match.cause,
1807
- })) ?? ({} as any)
1796
+ const beforeLoadFnContext = {
1797
+ search: match.search,
1798
+ abortController,
1799
+ params: match.params,
1800
+ preload: !!preload,
1801
+ context: match.routeContext,
1802
+ location,
1803
+ navigate: (opts: any) =>
1804
+ this.navigate({ ...opts, _fromLocation: location }),
1805
+ buildLocation: this.buildLocation,
1806
+ cause: preload ? 'preload' : match.cause,
1807
+ }
1808
+
1809
+ const beforeLoadContext = route.options.beforeLoad
1810
+ ? (await route.options.beforeLoad(beforeLoadFnContext)) ?? {}
1811
+ : {}
1808
1812
 
1809
1813
  checkLatest()
1810
1814
 
@@ -1860,7 +1864,7 @@ export class Router<
1860
1864
  route,
1861
1865
  }
1862
1866
 
1863
- const fetch = async () => {
1867
+ const fetchAndResolveInLoaderLifetime = async () => {
1864
1868
  const existing = getRouteMatch(this.state, match.id)!
1865
1869
  let lazyPromise = Promise.resolve()
1866
1870
  let componentsPromise = Promise.resolve() as Promise<any>
@@ -2035,7 +2039,7 @@ export class Router<
2035
2039
 
2036
2040
  const fetchWithRedirectAndNotFound = async () => {
2037
2041
  try {
2038
- await fetch()
2042
+ await fetchAndResolveInLoaderLifetime()
2039
2043
  } catch (err) {
2040
2044
  checkLatest()
2041
2045
  handleRedirectAndNotFound(match, err)
@@ -2246,7 +2250,10 @@ export class Router<
2246
2250
  return false
2247
2251
  }
2248
2252
 
2249
- const baseLocation = opts?.pending
2253
+ const pending =
2254
+ opts?.pending === undefined ? !this.state.isLoading : opts.pending
2255
+
2256
+ const baseLocation = pending
2250
2257
  ? this.latestLocation
2251
2258
  : this.state.resolvedLocation
2252
2259