@tanstack/react-router 1.139.0 → 1.139.3

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/fileRoute.ts CHANGED
@@ -89,14 +89,6 @@ export function createFileRoute<
89
89
  @deprecated It's no longer recommended to use the `FileRoute` class directly.
90
90
  Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
91
91
  */
92
- /**
93
- @deprecated It's no longer recommended to use the `FileRoute` class directly.
94
- Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
95
- */
96
- /**
97
- @deprecated It's no longer recommended to use the `FileRoute` class directly.
98
- Instead, use `createFileRoute('/path')(options)` to create a file route.
99
- */
100
92
  export class FileRoute<
101
93
  TFilePath extends keyof FileRoutesByPath,
102
94
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
@@ -3,6 +3,14 @@ import warning from 'tiny-warning'
3
3
  import { DefaultGlobalNotFound } from './not-found'
4
4
  import type { AnyRoute, AnyRouter } from '@tanstack/router-core'
5
5
 
6
+ /**
7
+ * Renders a not found component for a route when no matching route is found.
8
+ *
9
+ * @param router - The router instance containing the route configuration
10
+ * @param route - The route that triggered the not found state
11
+ * @param data - Additional data to pass to the not found component
12
+ * @returns The rendered not found component or a default fallback component
13
+ */
6
14
  export function renderRouteNotFound(
7
15
  router: AnyRouter,
8
16
  route: AnyRoute,
@@ -16,7 +24,7 @@ export function renderRouteNotFound(
16
24
  if (process.env.NODE_ENV === 'development') {
17
25
  warning(
18
26
  route.options.notFoundComponent,
19
- `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`,
27
+ `A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<p>Not Found</p>)`,
20
28
  )
21
29
  }
22
30
 
@@ -179,20 +179,34 @@ export function useBlocker(
179
179
  const parsedLocation = router.parseLocation(location)
180
180
  const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)
181
181
  if (matchedRoutes.foundRoute === undefined) {
182
- throw new Error(`No route found for location ${location.href}`)
182
+ return {
183
+ routeId: '__notFound__',
184
+ fullPath: parsedLocation.pathname,
185
+ pathname: parsedLocation.pathname,
186
+ params: matchedRoutes.routeParams,
187
+ search: router.options.parseSearch(location.search),
188
+ }
183
189
  }
190
+
184
191
  return {
185
192
  routeId: matchedRoutes.foundRoute.id,
186
193
  fullPath: matchedRoutes.foundRoute.fullPath,
187
194
  pathname: parsedLocation.pathname,
188
195
  params: matchedRoutes.routeParams,
189
- search: parsedLocation.search,
196
+ search: router.options.parseSearch(location.search),
190
197
  }
191
198
  }
192
199
 
193
200
  const current = getLocation(blockerFnArgs.currentLocation)
194
201
  const next = getLocation(blockerFnArgs.nextLocation)
195
202
 
203
+ if (
204
+ current.routeId === '__notFound__' &&
205
+ next.routeId !== '__notFound__'
206
+ ) {
207
+ return false
208
+ }
209
+
196
210
  const shouldBlock = await shouldBlockFn({
197
211
  action: blockerFnArgs.action,
198
212
  current,