@tanstack/react-router 1.133.20 → 1.133.22

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.
Files changed (81) hide show
  1. package/dist/cjs/Match.cjs.map +1 -1
  2. package/dist/cjs/Match.d.cts +6 -0
  3. package/dist/cjs/Matches.cjs.map +1 -1
  4. package/dist/cjs/Matches.d.cts +42 -0
  5. package/dist/cjs/RouterProvider.cjs.map +1 -1
  6. package/dist/cjs/RouterProvider.d.cts +13 -0
  7. package/dist/cjs/fileRoute.cjs.map +1 -1
  8. package/dist/cjs/fileRoute.d.cts +43 -0
  9. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  10. package/dist/cjs/lazyRouteComponent.d.cts +9 -0
  11. package/dist/cjs/link.cjs.map +1 -1
  12. package/dist/cjs/link.d.cts +13 -1
  13. package/dist/cjs/route.cjs.map +1 -1
  14. package/dist/cjs/route.d.cts +18 -0
  15. package/dist/cjs/useLoaderData.cjs.map +1 -1
  16. package/dist/cjs/useLoaderData.d.cts +11 -0
  17. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  18. package/dist/cjs/useLoaderDeps.d.cts +11 -0
  19. package/dist/cjs/useLocation.cjs.map +1 -1
  20. package/dist/cjs/useLocation.d.cts +11 -0
  21. package/dist/cjs/useMatch.cjs.map +1 -1
  22. package/dist/cjs/useMatch.d.cts +12 -0
  23. package/dist/cjs/useNavigate.cjs.map +1 -1
  24. package/dist/cjs/useNavigate.d.cts +8 -4
  25. package/dist/cjs/useParams.cjs.map +1 -1
  26. package/dist/cjs/useParams.d.cts +12 -0
  27. package/dist/cjs/useRouter.cjs.map +1 -1
  28. package/dist/cjs/useRouter.d.cts +20 -0
  29. package/dist/cjs/useRouterState.cjs.map +1 -1
  30. package/dist/cjs/useRouterState.d.cts +12 -0
  31. package/dist/cjs/useSearch.cjs.map +1 -1
  32. package/dist/cjs/useSearch.d.cts +12 -0
  33. package/dist/esm/Match.d.ts +6 -0
  34. package/dist/esm/Match.js.map +1 -1
  35. package/dist/esm/Matches.d.ts +42 -0
  36. package/dist/esm/Matches.js.map +1 -1
  37. package/dist/esm/RouterProvider.d.ts +13 -0
  38. package/dist/esm/RouterProvider.js.map +1 -1
  39. package/dist/esm/fileRoute.d.ts +43 -0
  40. package/dist/esm/fileRoute.js.map +1 -1
  41. package/dist/esm/lazyRouteComponent.d.ts +9 -0
  42. package/dist/esm/lazyRouteComponent.js.map +1 -1
  43. package/dist/esm/link.d.ts +13 -1
  44. package/dist/esm/link.js.map +1 -1
  45. package/dist/esm/route.d.ts +18 -0
  46. package/dist/esm/route.js.map +1 -1
  47. package/dist/esm/useLoaderData.d.ts +11 -0
  48. package/dist/esm/useLoaderData.js.map +1 -1
  49. package/dist/esm/useLoaderDeps.d.ts +11 -0
  50. package/dist/esm/useLoaderDeps.js.map +1 -1
  51. package/dist/esm/useLocation.d.ts +11 -0
  52. package/dist/esm/useLocation.js.map +1 -1
  53. package/dist/esm/useMatch.d.ts +12 -0
  54. package/dist/esm/useMatch.js.map +1 -1
  55. package/dist/esm/useNavigate.d.ts +8 -4
  56. package/dist/esm/useNavigate.js.map +1 -1
  57. package/dist/esm/useParams.d.ts +12 -0
  58. package/dist/esm/useParams.js.map +1 -1
  59. package/dist/esm/useRouter.d.ts +20 -0
  60. package/dist/esm/useRouter.js.map +1 -1
  61. package/dist/esm/useRouterState.d.ts +12 -0
  62. package/dist/esm/useRouterState.js.map +1 -1
  63. package/dist/esm/useSearch.d.ts +12 -0
  64. package/dist/esm/useSearch.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/Match.tsx +6 -0
  67. package/src/Matches.tsx +43 -0
  68. package/src/RouterProvider.tsx +13 -0
  69. package/src/fileRoute.ts +43 -0
  70. package/src/lazyRouteComponent.tsx +9 -0
  71. package/src/link.tsx +13 -1
  72. package/src/route.tsx +18 -0
  73. package/src/useLoaderData.tsx +11 -0
  74. package/src/useLoaderDeps.tsx +11 -0
  75. package/src/useLocation.tsx +11 -0
  76. package/src/useMatch.tsx +12 -0
  77. package/src/useNavigate.tsx +8 -4
  78. package/src/useParams.tsx +12 -0
  79. package/src/useRouter.tsx +20 -0
  80. package/src/useRouterState.tsx +12 -0
  81. package/src/useSearch.tsx +12 -0
package/src/fileRoute.ts CHANGED
@@ -35,6 +35,17 @@ import type { UseLoaderDepsRoute } from './useLoaderDeps'
35
35
  import type { UseLoaderDataRoute } from './useLoaderData'
36
36
  import type { UseRouteContextRoute } from './useRouteContext'
37
37
 
38
+ /**
39
+ * Creates a file-based Route factory for a given path.
40
+ *
41
+ * Used by TanStack Router's file-based routing to associate a file with a
42
+ * route. The returned function accepts standard route options. In normal usage
43
+ * the `path` string is inserted and maintained by the `tsr` generator.
44
+ *
45
+ * @param path File path literal for the route (usually auto-generated).
46
+ * @returns A function that accepts Route options and returns a Route instance.
47
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction
48
+ */
38
49
  /**
39
50
  * Creates a file-based Route factory for a given path.
40
51
  *
@@ -66,6 +77,10 @@ export function createFileRoute<
66
77
  }).createRoute
67
78
  }
68
79
 
80
+ /**
81
+ @deprecated It's no longer recommended to use the `FileRoute` class directly.
82
+ Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
83
+ */
69
84
  /**
70
85
  @deprecated It's no longer recommended to use the `FileRoute` class directly.
71
86
  Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
@@ -159,6 +174,11 @@ export class FileRoute<
159
174
  }
160
175
  }
161
176
 
177
+ /**
178
+ @deprecated It's recommended not to split loaders into separate files.
179
+ Instead, place the loader function in the the main route file, inside the
180
+ `createFileRoute('/path/to/file)(options)` options.
181
+ */
162
182
  /**
163
183
  @deprecated It's recommended not to split loaders into separate files.
164
184
  Instead, place the loader function in the the main route file, inside the
@@ -264,6 +284,18 @@ export class LazyRoute<TRoute extends AnyRoute> {
264
284
  }
265
285
  }
266
286
 
287
+ /**
288
+ * Creates a lazily-configurable code-based route stub by ID.
289
+ *
290
+ * Use this for code-splitting with code-based routes. The returned function
291
+ * accepts only non-critical route options like `component`, `pendingComponent`,
292
+ * `errorComponent`, and `notFoundComponent` which are applied when the route
293
+ * is matched.
294
+ *
295
+ * @param id Route ID string literal to associate with the lazy route.
296
+ * @returns A function that accepts lazy route options and returns a `LazyRoute`.
297
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction
298
+ */
267
299
  /**
268
300
  * Creates a lazily-configurable code-based route stub by ID.
269
301
  *
@@ -289,6 +321,17 @@ export function createLazyRoute<
289
321
  }
290
322
  }
291
323
 
324
+ /**
325
+ * Creates a lazily-configurable file-based route stub by file path.
326
+ *
327
+ * Use this for code-splitting with file-based routes (eg. `.lazy.tsx` files).
328
+ * The returned function accepts only non-critical route options like
329
+ * `component`, `pendingComponent`, `errorComponent`, and `notFoundComponent`.
330
+ *
331
+ * @param id File path literal for the route file.
332
+ * @returns A function that accepts lazy route options and returns a `LazyRoute`.
333
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction
334
+ */
292
335
  /**
293
336
  * Creates a lazily-configurable file-based route stub by file path.
294
337
  *
@@ -2,6 +2,15 @@ import * as React from 'react'
2
2
  import { isModuleNotFoundError } from '@tanstack/router-core'
3
3
  import type { AsyncRouteComponent } from './route'
4
4
 
5
+ /**
6
+ * Wrap a dynamic import to create a route component that supports
7
+ * `.preload()` and friendly reload-on-module-missing behavior.
8
+ *
9
+ * @param importer Function returning a module promise
10
+ * @param exportName Named export to use (default: `default`)
11
+ * @returns A lazy route component compatible with TanStack Router
12
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/lazyRouteComponentFunction
13
+ */
5
14
  export function lazyRouteComponent<
6
15
  T extends Record<string, any>,
7
16
  TKey extends keyof T = 'default',
package/src/link.tsx CHANGED
@@ -25,6 +25,18 @@ import type {
25
25
  ValidateLinkOptionsArray,
26
26
  } from './typePrimitives'
27
27
 
28
+ /**
29
+ * Build anchor-like props for declarative navigation and preloading.
30
+ *
31
+ * Returns stable `href`, event handlers and accessibility props derived from
32
+ * router options and active state. Used internally by `Link` and custom links.
33
+ *
34
+ * Options cover `to`, `params`, `search`, `hash`, `state`, `preload`,
35
+ * `activeProps`, `inactiveProps`, and more.
36
+ *
37
+ * @returns React anchor props suitable for `<a>` or custom components.
38
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLinkPropsHook
39
+ */
28
40
  export function useLinkProps<
29
41
  TRouter extends AnyRouter = RegisteredRouter,
30
42
  const TFrom extends string = string,
@@ -539,7 +551,7 @@ export function createLink<const TComp>(
539
551
  * Handles path, search, hash and state updates with optional route preloading
540
552
  * and active-state styling.
541
553
  *
542
- * Non-obvious props include:
554
+ * Props:
543
555
  * - `preload`: Controls route preloading (eg. 'intent', 'render', 'viewport', true/false)
544
556
  * - `preloadDelay`: Delay in ms before preloading on hover
545
557
  * - `activeProps`/`inactiveProps`: Additional props merged when link is active/inactive
package/src/route.tsx CHANGED
@@ -78,6 +78,24 @@ declare module '@tanstack/router-core' {
78
78
  }
79
79
  }
80
80
 
81
+ /**
82
+ * Returns a route-specific API that exposes type-safe hooks pre-bound
83
+ * to a single route ID. Useful for consuming a route's APIs from files
84
+ * where the route object isn't directly imported (e.g. code-split files).
85
+ *
86
+ * @param id Route ID string literal for the target route.
87
+ * @returns A `RouteApi` instance bound to the given route ID.
88
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/getRouteApiFunction
89
+ */
90
+ /**
91
+ * Returns a route-specific API that exposes type-safe hooks pre-bound
92
+ * to a single route ID. Useful for consuming a route's APIs from files
93
+ * where the route object isn't directly imported (e.g. code-split files).
94
+ *
95
+ * @param id Route ID string literal for the target route.
96
+ * @returns A `RouteApi` instance bound to the given route ID.
97
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/getRouteApiFunction
98
+ */
81
99
  /**
82
100
  * Returns a route-specific API that exposes type-safe hooks pre-bound
83
101
  * to a single route ID. Useful for consuming a route's APIs from files
@@ -54,6 +54,17 @@ export type UseLoaderDataRoute<out TId> = <
54
54
  StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
55
55
  ) => UseLoaderDataResult<TRouter, TId, true, TSelected>
56
56
 
57
+ /**
58
+ * Read and select the current route's loader data with type‑safety.
59
+ *
60
+ * Options:
61
+ * - `from`/`strict`: Choose which route's data to read and strictness
62
+ * - `select`: Map the loader data to a derived value
63
+ * - `structuralSharing`: Enable structural sharing for stable references
64
+ *
65
+ * @returns The loader data (or selected value) for the matched route.
66
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDataHook
67
+ */
57
68
  export function useLoaderData<
58
69
  TRouter extends AnyRouter = RegisteredRouter,
59
70
  const TFrom extends string | undefined = undefined,
@@ -40,6 +40,17 @@ export type UseLoaderDepsRoute<out TId> = <
40
40
  StructuralSharingOption<TRouter, TSelected, false>,
41
41
  ) => UseLoaderDepsResult<TRouter, TId, TSelected>
42
42
 
43
+ /**
44
+ * Read and select the current route's loader dependencies object.
45
+ *
46
+ * Options:
47
+ * - `from`: Choose which route's loader deps to read
48
+ * - `select`: Map the deps to a derived value
49
+ * - `structuralSharing`: Enable structural sharing for stable references
50
+ *
51
+ * @returns The loader deps (or selected value) for the matched route.
52
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDepsHook
53
+ */
43
54
  export function useLoaderDeps<
44
55
  TRouter extends AnyRouter = RegisteredRouter,
45
56
  const TFrom extends string | undefined = undefined,
@@ -26,6 +26,17 @@ export type UseLocationResult<
26
26
  ? RouterState<TRouter['routeTree']>['location']
27
27
  : TSelected
28
28
 
29
+ /**
30
+ * Read the current location from the router state with optional selection.
31
+ * Useful for subscribing to just the pieces of location you care about.
32
+ *
33
+ * Options:
34
+ * - `select`: Project the `location` object to a derived value
35
+ * - `structuralSharing`: Enable structural sharing for stable references
36
+ *
37
+ * @returns The current location (or selected value).
38
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook
39
+ */
29
40
  export function useLocation<
30
41
  TRouter extends AnyRouter = RegisteredRouter,
31
42
  TSelected = unknown,
package/src/useMatch.tsx CHANGED
@@ -75,6 +75,18 @@ export type UseMatchResult<
75
75
  : MakeRouteMatchUnion<TRouter>
76
76
  : TSelected
77
77
 
78
+ /**
79
+ * Read and select the nearest or targeted route match.
80
+ *
81
+ * Options:
82
+ * - `from`/`strict`: Target a specific route ID and control union vs. exact typing
83
+ * - `select`: Project the match object to a derived value
84
+ * - `shouldThrow`: Throw if the match is not found in strict contexts
85
+ * - `structuralSharing`: Enable structural sharing for stable references
86
+ *
87
+ * @returns The active match (or selected value).
88
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook
89
+ */
78
90
  export function useMatch<
79
91
  TRouter extends AnyRouter = RegisteredRouter,
80
92
  const TFrom extends string | undefined = undefined,
@@ -9,13 +9,17 @@ import type {
9
9
  } from '@tanstack/router-core'
10
10
 
11
11
  /**
12
- * React hook that returns a `navigate` function for programmatic navigation.
13
- * Supports updating pathname, search, hash and state with full type-safety.
12
+ * Imperative navigation hook.
13
+ *
14
+ * Returns a stable `navigate(options)` function to change the current location
15
+ * programmatically. Prefer the `Link` component for user-initiated navigation,
16
+ * and use this hook from effects, callbacks, or handlers where imperative
17
+ * navigation is required.
14
18
  *
15
19
  * Options:
16
- * - `from`: Default base path used to resolve relative `to` destinations.
20
+ * - `from`: Optional route base used to resolve relative `to` paths.
17
21
  *
18
- * @returns A memoized `navigate` function.
22
+ * @returns A function that accepts `NavigateOptions`.
19
23
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useNavigateHook
20
24
  */
21
25
  export function useNavigate<
package/src/useParams.tsx CHANGED
@@ -61,6 +61,18 @@ export type UseParamsRoute<out TFrom> = <
61
61
  StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
62
62
  ) => UseParamsResult<TRouter, TFrom, true, TSelected>
63
63
 
64
+ /**
65
+ * Access the current route's path parameters with type-safety.
66
+ *
67
+ * Options:
68
+ * - `from`/`strict`: Specify the matched route and whether to enforce strict typing
69
+ * - `select`: Project the params object to a derived value for memoized renders
70
+ * - `structuralSharing`: Enable structural sharing for stable references
71
+ * - `shouldThrow`: Throw if the route is not found in strict contexts
72
+ *
73
+ * @returns The params object (or selected value) for the matched route.
74
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
75
+ */
64
76
  export function useParams<
65
77
  TRouter extends AnyRouter = RegisteredRouter,
66
78
  const TFrom extends string | undefined = undefined,
package/src/useRouter.tsx CHANGED
@@ -3,6 +3,26 @@ import warning from 'tiny-warning'
3
3
  import { getRouterContext } from './routerContext'
4
4
  import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
5
5
 
6
+ /**
7
+ * Access the current TanStack Router instance from React context.
8
+ * Must be used within a `RouterProvider`.
9
+ *
10
+ * Options:
11
+ * - `warn`: Log a warning if no router context is found (default: true).
12
+ *
13
+ * @returns The registered router instance.
14
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
15
+ */
16
+ /**
17
+ * Access the current TanStack Router instance from React context.
18
+ * Must be used within a `RouterProvider`.
19
+ *
20
+ * Options:
21
+ * - `warn`: Log a warning if no router context is found (default: true).
22
+ *
23
+ * @returns The registered router instance.
24
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
25
+ */
6
26
  export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
7
27
  warn?: boolean
8
28
  }): TRouter {
@@ -28,6 +28,18 @@ export type UseRouterStateResult<
28
28
  TSelected,
29
29
  > = unknown extends TSelected ? RouterState<TRouter['routeTree']> : TSelected
30
30
 
31
+ /**
32
+ * Subscribe to the router's state store with optional selection and
33
+ * structural sharing for render optimization.
34
+ *
35
+ * Options:
36
+ * - `select`: Project the full router state to a derived slice
37
+ * - `structuralSharing`: Replace-equal semantics for stable references
38
+ * - `router`: Read state from a specific router instance instead of context
39
+ *
40
+ * @returns The selected router state (or the full state by default).
41
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
42
+ */
31
43
  export function useRouterState<
32
44
  TRouter extends AnyRouter = RegisteredRouter,
33
45
  TSelected = unknown,
package/src/useSearch.tsx CHANGED
@@ -61,6 +61,18 @@ export type UseSearchRoute<out TFrom> = <
61
61
  StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,
62
62
  ) => UseSearchResult<TRouter, TFrom, true, TSelected>
63
63
 
64
+ /**
65
+ * Read and select the current route's search parameters with type-safety.
66
+ *
67
+ * Options:
68
+ * - `from`/`strict`: Control which route's search is read and how strictly it's typed
69
+ * - `select`: Map the search object to a derived value for render optimization
70
+ * - `structuralSharing`: Enable structural sharing for stable references
71
+ * - `shouldThrow`: Throw when the route is not found (strict contexts)
72
+ *
73
+ * @returns The search object (or selected value) for the matched route.
74
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
75
+ */
64
76
  export function useSearch<
65
77
  TRouter extends AnyRouter = RegisteredRouter,
66
78
  const TFrom extends string | undefined = undefined,