@tanstack/router-core 1.136.11 → 1.136.14

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
@@ -1388,7 +1388,7 @@ export class RouterCore<
1388
1388
 
1389
1389
  const strictParams = existingMatch?._strictParams ?? usedParams
1390
1390
 
1391
- let paramsError: PathParamError | undefined = undefined
1391
+ let paramsError: unknown = undefined
1392
1392
 
1393
1393
  if (!existingMatch) {
1394
1394
  const strictParseParams =
@@ -1401,9 +1401,13 @@ export class RouterCore<
1401
1401
  strictParseParams(strictParams as Record<string, string>),
1402
1402
  )
1403
1403
  } catch (err: any) {
1404
- paramsError = new PathParamError(err.message, {
1405
- cause: err,
1406
- })
1404
+ if (isNotFound(err) || isRedirect(err)) {
1405
+ paramsError = err
1406
+ } else {
1407
+ paramsError = new PathParamError(err.message, {
1408
+ cause: err,
1409
+ })
1410
+ }
1407
1411
 
1408
1412
  if (opts?.throwOnError) {
1409
1413
  throw paramsError
@@ -2130,9 +2134,18 @@ export class RouterCore<
2130
2134
  loadedAt: Date.now(),
2131
2135
  matches: newMatches,
2132
2136
  pendingMatches: undefined,
2137
+ /**
2138
+ * When committing new matches, cache any exiting matches that are still usable.
2139
+ * Routes that resolved with `status: 'error'` or `status: 'notFound'` are
2140
+ * deliberately excluded from `cachedMatches` so that subsequent invalidations
2141
+ * or reloads re-run their loaders instead of reusing the failed/not-found data.
2142
+ */
2133
2143
  cachedMatches: [
2134
2144
  ...s.cachedMatches,
2135
- ...exitingMatches.filter((d) => d.status !== 'error'),
2145
+ ...exitingMatches.filter(
2146
+ (d) =>
2147
+ d.status !== 'error' && d.status !== 'notFound',
2148
+ ),
2136
2149
  ],
2137
2150
  }
2138
2151
  })
@@ -2304,6 +2317,14 @@ export class RouterCore<
2304
2317
  )
2305
2318
  }
2306
2319
 
2320
+ /**
2321
+ * Invalidate the current matches and optionally force them back into a pending state.
2322
+ *
2323
+ * - Marks all matches that pass the optional `filter` as `invalid: true`.
2324
+ * - If `forcePending` is true, or a match is currently in `'error'` or `'notFound'` status,
2325
+ * its status is reset to `'pending'` and its `error` cleared so that the loader is re-run
2326
+ * on the next `load()` call (eg. after HMR or a manual invalidation).
2327
+ */
2307
2328
  invalidate: InvalidateFn<
2308
2329
  RouterCore<
2309
2330
  TRouteTree,
@@ -2318,7 +2339,9 @@ export class RouterCore<
2318
2339
  return {
2319
2340
  ...d,
2320
2341
  invalid: true,
2321
- ...(opts?.forcePending || d.status === 'error'
2342
+ ...(opts?.forcePending ||
2343
+ d.status === 'error' ||
2344
+ d.status === 'notFound'
2322
2345
  ? ({ status: 'pending', error: undefined } as const)
2323
2346
  : undefined),
2324
2347
  }