@tanstack/react-router 1.133.27 → 1.133.32

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 (97) hide show
  1. package/dist/cjs/ClientOnly.cjs.map +1 -1
  2. package/dist/cjs/ClientOnly.d.cts +5 -0
  3. package/dist/cjs/HeadContent.cjs.map +1 -1
  4. package/dist/cjs/HeadContent.d.cts +9 -0
  5. package/dist/cjs/Matches.cjs.map +1 -1
  6. package/dist/cjs/Matches.d.cts +12 -0
  7. package/dist/cjs/RouterProvider.cjs.map +1 -1
  8. package/dist/cjs/RouterProvider.d.cts +9 -0
  9. package/dist/cjs/ScriptOnce.cjs.map +1 -1
  10. package/dist/cjs/ScriptOnce.d.cts +4 -0
  11. package/dist/cjs/Scripts.cjs.map +1 -1
  12. package/dist/cjs/Scripts.d.cts +4 -0
  13. package/dist/cjs/awaited.cjs.map +1 -1
  14. package/dist/cjs/awaited.d.cts +5 -0
  15. package/dist/cjs/fileRoute.cjs.map +1 -1
  16. package/dist/cjs/fileRoute.d.cts +23 -0
  17. package/dist/cjs/link.cjs +1 -1
  18. package/dist/cjs/link.cjs.map +1 -1
  19. package/dist/cjs/link.d.cts +14 -0
  20. package/dist/cjs/router.cjs.map +1 -1
  21. package/dist/cjs/router.d.cts +5 -0
  22. package/dist/cjs/useLoaderData.cjs.map +1 -1
  23. package/dist/cjs/useLoaderData.d.cts +4 -0
  24. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  25. package/dist/cjs/useLoaderDeps.d.cts +4 -0
  26. package/dist/cjs/useLocation.cjs.map +1 -1
  27. package/dist/cjs/useLocation.d.cts +5 -0
  28. package/dist/cjs/useMatch.cjs.map +1 -1
  29. package/dist/cjs/useMatch.d.cts +0 -8
  30. package/dist/cjs/useParams.cjs.map +1 -1
  31. package/dist/cjs/useParams.d.cts +4 -0
  32. package/dist/cjs/useRouter.cjs.map +1 -1
  33. package/dist/cjs/useRouter.d.cts +5 -0
  34. package/dist/cjs/useRouterState.cjs.map +1 -1
  35. package/dist/cjs/useRouterState.d.cts +5 -0
  36. package/dist/cjs/useSearch.cjs.map +1 -1
  37. package/dist/cjs/useSearch.d.cts +4 -0
  38. package/dist/esm/ClientOnly.d.ts +5 -0
  39. package/dist/esm/ClientOnly.js.map +1 -1
  40. package/dist/esm/HeadContent.d.ts +9 -0
  41. package/dist/esm/HeadContent.js.map +1 -1
  42. package/dist/esm/Matches.d.ts +12 -0
  43. package/dist/esm/Matches.js.map +1 -1
  44. package/dist/esm/RouterProvider.d.ts +9 -0
  45. package/dist/esm/RouterProvider.js.map +1 -1
  46. package/dist/esm/ScriptOnce.d.ts +4 -0
  47. package/dist/esm/ScriptOnce.js.map +1 -1
  48. package/dist/esm/Scripts.d.ts +4 -0
  49. package/dist/esm/Scripts.js.map +1 -1
  50. package/dist/esm/awaited.d.ts +5 -0
  51. package/dist/esm/awaited.js.map +1 -1
  52. package/dist/esm/fileRoute.d.ts +23 -0
  53. package/dist/esm/fileRoute.js.map +1 -1
  54. package/dist/esm/link.d.ts +14 -0
  55. package/dist/esm/link.js +1 -1
  56. package/dist/esm/link.js.map +1 -1
  57. package/dist/esm/router.d.ts +5 -0
  58. package/dist/esm/router.js.map +1 -1
  59. package/dist/esm/useLoaderData.d.ts +4 -0
  60. package/dist/esm/useLoaderData.js.map +1 -1
  61. package/dist/esm/useLoaderDeps.d.ts +4 -0
  62. package/dist/esm/useLoaderDeps.js.map +1 -1
  63. package/dist/esm/useLocation.d.ts +5 -0
  64. package/dist/esm/useLocation.js.map +1 -1
  65. package/dist/esm/useMatch.d.ts +0 -8
  66. package/dist/esm/useMatch.js.map +1 -1
  67. package/dist/esm/useParams.d.ts +4 -0
  68. package/dist/esm/useParams.js.map +1 -1
  69. package/dist/esm/useRouter.d.ts +5 -0
  70. package/dist/esm/useRouter.js.map +1 -1
  71. package/dist/esm/useRouterState.d.ts +5 -0
  72. package/dist/esm/useRouterState.js.map +1 -1
  73. package/dist/esm/useSearch.d.ts +4 -0
  74. package/dist/esm/useSearch.js.map +1 -1
  75. package/dist/llms/rules/installation.d.ts +1 -1
  76. package/dist/llms/rules/installation.js +1 -1
  77. package/dist/llms/rules/setup-and-architecture.d.ts +1 -1
  78. package/dist/llms/rules/setup-and-architecture.js +7 -7
  79. package/package.json +3 -3
  80. package/src/ClientOnly.tsx +8 -0
  81. package/src/HeadContent.tsx +9 -0
  82. package/src/Matches.tsx +12 -0
  83. package/src/RouterProvider.tsx +9 -0
  84. package/src/ScriptOnce.tsx +4 -0
  85. package/src/Scripts.tsx +4 -0
  86. package/src/awaited.tsx +5 -0
  87. package/src/fileRoute.ts +23 -0
  88. package/src/link.tsx +18 -1
  89. package/src/router.ts +5 -0
  90. package/src/useLoaderData.tsx +4 -0
  91. package/src/useLoaderDeps.tsx +4 -0
  92. package/src/useLocation.tsx +5 -0
  93. package/src/useMatch.tsx +0 -8
  94. package/src/useParams.tsx +4 -0
  95. package/src/useRouter.tsx +5 -0
  96. package/src/useRouterState.tsx +5 -0
  97. package/src/useSearch.tsx +4 -0
package/src/awaited.tsx CHANGED
@@ -8,6 +8,7 @@ export type AwaitOptions<T> = {
8
8
  }
9
9
 
10
10
  /** Suspend until a deferred promise resolves/rejects and return its data. */
11
+ /** Suspend until a deferred promise resolves or rejects and return its data. */
11
12
  export function useAwaited<T>({
12
13
  promise: _promise,
13
14
  }: AwaitOptions<T>): [T, DeferredPromise<T>] {
@@ -24,6 +25,10 @@ export function useAwaited<T>({
24
25
  return [promise[TSR_DEFERRED_PROMISE].data, promise]
25
26
  }
26
27
 
28
+ /**
29
+ * Component that suspends on a deferred promise and renders its child with
30
+ * the resolved value. Optionally provides a Suspense fallback.
31
+ */
27
32
  /**
28
33
  * Component that suspends on a deferred promise and renders its child with
29
34
  * the resolved value. Optionally provides a Suspense fallback.
package/src/fileRoute.ts CHANGED
@@ -57,6 +57,13 @@ import type { UseRouteContextRoute } from './useRouteContext'
57
57
  * @returns A function that accepts Route options and returns a Route instance.
58
58
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction
59
59
  */
60
+ /**
61
+ * Creates a file-based Route factory for a given path.
62
+ * Used by file-based routing to associate a file with a route. The returned
63
+ * function accepts standard route options; the path is typically auto-managed
64
+ * by the generator.
65
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createFileRouteFunction
66
+ */
60
67
  export function createFileRoute<
61
68
  TFilePath extends keyof FileRoutesByPath,
62
69
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
@@ -85,6 +92,10 @@ export function createFileRoute<
85
92
  @deprecated It's no longer recommended to use the `FileRoute` class directly.
86
93
  Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
87
94
  */
95
+ /**
96
+ @deprecated It's no longer recommended to use the `FileRoute` class directly.
97
+ Instead, use `createFileRoute('/path')(options)` to create a file route.
98
+ */
88
99
  export class FileRoute<
89
100
  TFilePath extends keyof FileRoutesByPath,
90
101
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
@@ -184,6 +195,10 @@ export class FileRoute<
184
195
  Instead, place the loader function in the the main route file, inside the
185
196
  `createFileRoute('/path/to/file)(options)` options.
186
197
  */
198
+ /**
199
+ @deprecated It's recommended not to split loaders into separate files.
200
+ Instead, place the loader function in the main route file via `createFileRoute`.
201
+ */
187
202
  export function FileRouteLoader<
188
203
  TFilePath extends keyof FileRoutesByPath,
189
204
  TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
@@ -308,6 +323,10 @@ export class LazyRoute<TRoute extends AnyRoute> {
308
323
  * @returns A function that accepts lazy route options and returns a `LazyRoute`.
309
324
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction
310
325
  */
326
+ /**
327
+ * Create a lazily-configurable code-based route stub by ID.
328
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyRouteFunction
329
+ */
311
330
  export function createLazyRoute<
312
331
  TRouter extends AnyRouter = RegisteredRouter,
313
332
  TId extends string = string,
@@ -343,6 +362,10 @@ export function createLazyRoute<
343
362
  * @returns A function that accepts lazy route options and returns a `LazyRoute`.
344
363
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction
345
364
  */
365
+ /**
366
+ * Create a lazily-configurable file-based route stub by file path.
367
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createLazyFileRouteFunction
368
+ */
346
369
  export function createLazyFileRoute<
347
370
  TFilePath extends keyof FileRoutesByPath,
348
371
  TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
package/src/link.tsx CHANGED
@@ -243,7 +243,9 @@ export function useLinkProps<
243
243
  // The click handler
244
244
  const handleClick = (e: React.MouseEvent) => {
245
245
  // Check actual element's target attribute as fallback
246
- const elementTarget = (e.currentTarget as HTMLAnchorElement).target
246
+ const elementTarget = (
247
+ e.currentTarget as HTMLAnchorElement | SVGAElement
248
+ ).getAttribute('target')
247
249
  const effectiveTarget = target !== undefined ? target : elementTarget
248
250
 
249
251
  if (
@@ -615,6 +617,21 @@ export type LinkOptionsFn<TComp> = <
615
617
  options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,
616
618
  ) => TOptions
617
619
 
620
+ /**
621
+ * Validate and reuse navigation options for `Link`, `navigate` or `redirect`.
622
+ * Accepts a literal options object and returns it typed for later spreading.
623
+ * @example
624
+ * const opts = linkOptions({ to: '/dashboard', search: { tab: 'home' } })
625
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/linkOptions
626
+ */
618
627
  export const linkOptions: LinkOptionsFn<'a'> = (options) => {
619
628
  return options as any
620
629
  }
630
+
631
+ /**
632
+ * Type-check a literal object for use with `Link`, `navigate` or `redirect`.
633
+ * Use to validate and reuse navigation options across your app.
634
+ * @example
635
+ * const opts = linkOptions({ to: '/dashboard', search: { tab: 'home' } })
636
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/linkOptions
637
+ */
package/src/router.ts CHANGED
@@ -88,6 +88,11 @@ declare module '@tanstack/router-core' {
88
88
  * @returns A Router instance to be provided to `RouterProvider`.
89
89
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction
90
90
  */
91
+ /**
92
+ * Create a new React router instance from `RouterOptions`.
93
+ * Pass the resulting router to `RouterProvider`.
94
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction
95
+ */
91
96
  export const createRouter: CreateRouterFn = (options) => {
92
97
  return new Router(options)
93
98
  }
@@ -65,6 +65,10 @@ export type UseLoaderDataRoute<out TId> = <
65
65
  * @returns The loader data (or selected value) for the matched route.
66
66
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDataHook
67
67
  */
68
+ /**
69
+ * Read and select the current route's loader data with type‑safety.
70
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDataHook
71
+ */
68
72
  export function useLoaderData<
69
73
  TRouter extends AnyRouter = RegisteredRouter,
70
74
  const TFrom extends string | undefined = undefined,
@@ -51,6 +51,10 @@ export type UseLoaderDepsRoute<out TId> = <
51
51
  * @returns The loader deps (or selected value) for the matched route.
52
52
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDepsHook
53
53
  */
54
+ /**
55
+ * Read and select the current route's loader dependencies object.
56
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLoaderDepsHook
57
+ */
54
58
  export function useLoaderDeps<
55
59
  TRouter extends AnyRouter = RegisteredRouter,
56
60
  const TFrom extends string | undefined = undefined,
@@ -37,6 +37,11 @@ export type UseLocationResult<
37
37
  * @returns The current location (or selected value).
38
38
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook
39
39
  */
40
+ /**
41
+ * Read the current location from the router state with optional selection.
42
+ * Useful for subscribing to just the pieces of location you care about.
43
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useLocationHook
44
+ */
40
45
  export function useLocation<
41
46
  TRouter extends AnyRouter = RegisteredRouter,
42
47
  TSelected = unknown,
package/src/useMatch.tsx CHANGED
@@ -77,14 +77,6 @@ export type UseMatchResult<
77
77
 
78
78
  /**
79
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
80
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchHook
89
81
  */
90
82
  export function useMatch<
package/src/useParams.tsx CHANGED
@@ -73,6 +73,10 @@ export type UseParamsRoute<out TFrom> = <
73
73
  * @returns The params object (or selected value) for the matched route.
74
74
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
75
75
  */
76
+ /**
77
+ * Access the current route's path parameters with type-safety.
78
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook
79
+ */
76
80
  export function useParams<
77
81
  TRouter extends AnyRouter = RegisteredRouter,
78
82
  const TFrom extends string | undefined = undefined,
package/src/useRouter.tsx CHANGED
@@ -13,6 +13,11 @@ import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
13
13
  * @returns The registered router instance.
14
14
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
15
15
  */
16
+ /**
17
+ * Access the current TanStack Router instance from React context.
18
+ * Must be used within a `RouterProvider`.
19
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook
20
+ */
16
21
  export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
17
22
  warn?: boolean
18
23
  }): TRouter {
@@ -40,6 +40,11 @@ export type UseRouterStateResult<
40
40
  * @returns The selected router state (or the full state by default).
41
41
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
42
42
  */
43
+ /**
44
+ * Subscribe to the router's state store with optional selection and
45
+ * structural sharing for render optimization.
46
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
47
+ */
43
48
  export function useRouterState<
44
49
  TRouter extends AnyRouter = RegisteredRouter,
45
50
  TSelected = unknown,
package/src/useSearch.tsx CHANGED
@@ -73,6 +73,10 @@ export type UseSearchRoute<out TFrom> = <
73
73
  * @returns The search object (or selected value) for the matched route.
74
74
  * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
75
75
  */
76
+ /**
77
+ * Read and select the current route's search parameters with type-safety.
78
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useSearchHook
79
+ */
76
80
  export function useSearch<
77
81
  TRouter extends AnyRouter = RegisteredRouter,
78
82
  const TFrom extends string | undefined = undefined,