@tanstack/react-router 1.133.21 → 1.133.25
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/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Match.d.cts +6 -0
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +42 -0
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Scripts.d.cts +4 -0
- package/dist/cjs/ScrollRestoration.cjs.map +1 -1
- package/dist/cjs/ScrollRestoration.d.cts +1 -1
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/awaited.d.cts +5 -0
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +43 -0
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
- package/dist/cjs/lazyRouteComponent.d.cts +9 -0
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +12 -0
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +11 -0
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +11 -0
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useLocation.d.cts +11 -0
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +12 -0
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +8 -4
- package/dist/esm/Match.d.ts +6 -0
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +42 -0
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/Scripts.d.ts +4 -0
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/ScrollRestoration.d.ts +1 -1
- package/dist/esm/ScrollRestoration.js.map +1 -1
- package/dist/esm/awaited.d.ts +5 -0
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +43 -0
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/lazyRouteComponent.d.ts +9 -0
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/link.d.ts +12 -0
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +11 -0
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +11 -0
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useLocation.d.ts +11 -0
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.d.ts +12 -0
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +8 -4
- package/dist/esm/useNavigate.js.map +1 -1
- package/package.json +2 -2
- package/src/Match.tsx +6 -0
- package/src/Matches.tsx +43 -0
- package/src/Scripts.tsx +4 -0
- package/src/ScrollRestoration.tsx +1 -1
- package/src/awaited.tsx +5 -0
- package/src/fileRoute.ts +43 -0
- package/src/lazyRouteComponent.tsx +9 -0
- package/src/link.tsx +12 -0
- package/src/useLoaderData.tsx +11 -0
- package/src/useLoaderDeps.tsx +11 -0
- package/src/useLocation.tsx +11 -0
- package/src/useMatch.tsx +12 -0
- package/src/useNavigate.tsx +8 -4
package/src/Matches.tsx
CHANGED
|
@@ -41,6 +41,10 @@ declare module '@tanstack/router-core' {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Internal component that renders the router's active match tree with
|
|
46
|
+
* suspense, error, and not-found boundaries. Rendered by `RouterProvider`.
|
|
47
|
+
*/
|
|
44
48
|
export function Matches() {
|
|
45
49
|
const router = useRouter()
|
|
46
50
|
const rootRoute: AnyRoute = router.routesById[rootRouteId]
|
|
@@ -119,6 +123,18 @@ export type UseMatchRouteOptions<
|
|
|
119
123
|
MaskOptions<TRouter, TMaskFrom, TMaskTo> &
|
|
120
124
|
MatchRouteOptions
|
|
121
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Create a matcher function for testing locations against route definitions.
|
|
128
|
+
*
|
|
129
|
+
* The returned function accepts standard navigation options (`to`, `params`,
|
|
130
|
+
* `search`, etc.) and returns either `false` (no match) or the matched params
|
|
131
|
+
* object when the route matches the current or pending location.
|
|
132
|
+
*
|
|
133
|
+
* Useful for conditional rendering and active UI states.
|
|
134
|
+
*
|
|
135
|
+
* @returns A `matchRoute(options)` function that returns `false` or params.
|
|
136
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook
|
|
137
|
+
*/
|
|
122
138
|
export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
123
139
|
const router = useRouter()
|
|
124
140
|
|
|
@@ -169,6 +185,13 @@ export type MakeMatchRouteOptions<
|
|
|
169
185
|
| React.ReactNode
|
|
170
186
|
}
|
|
171
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Component that conditionally renders its children based on whether a route
|
|
190
|
+
* matches the provided `from`/`to` options. If `children` is a function, it
|
|
191
|
+
* receives the matched params object.
|
|
192
|
+
*
|
|
193
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent
|
|
194
|
+
*/
|
|
172
195
|
export function MatchRoute<
|
|
173
196
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
174
197
|
const TFrom extends string = string,
|
|
@@ -220,6 +243,22 @@ export function useMatches<
|
|
|
220
243
|
} as any) as UseMatchesResult<TRouter, TSelected>
|
|
221
244
|
}
|
|
222
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Read the full array of active route matches or select a derived subset.
|
|
248
|
+
*
|
|
249
|
+
* Useful for debugging, breadcrumbs, or aggregating metadata across matches.
|
|
250
|
+
*
|
|
251
|
+
* @returns The array of matches (or the selected value).
|
|
252
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Read the full array of active route matches or select a derived subset.
|
|
257
|
+
*
|
|
258
|
+
* Useful for debugging, breadcrumbs, or aggregating metadata across matches.
|
|
259
|
+
*
|
|
260
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook
|
|
261
|
+
*/
|
|
223
262
|
export function useParentMatches<
|
|
224
263
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
225
264
|
TSelected = unknown,
|
|
@@ -242,6 +281,10 @@ export function useParentMatches<
|
|
|
242
281
|
} as any)
|
|
243
282
|
}
|
|
244
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Read the array of active route matches that are children of the current
|
|
286
|
+
* match (or selected parent) in the match tree.
|
|
287
|
+
*/
|
|
245
288
|
export function useChildMatches<
|
|
246
289
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
247
290
|
TSelected = unknown,
|
package/src/Scripts.tsx
CHANGED
|
@@ -3,6 +3,10 @@ import { useRouterState } from './useRouterState'
|
|
|
3
3
|
import { useRouter } from './useRouter'
|
|
4
4
|
import type { RouterManagedTag } from '@tanstack/router-core'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Render body script tags collected from route matches and SSR manifests.
|
|
8
|
+
* Should be placed near the end of the document body.
|
|
9
|
+
*/
|
|
6
10
|
export const Scripts = () => {
|
|
7
11
|
const router = useRouter()
|
|
8
12
|
const nonce = router.options.ssr?.nonce
|
|
@@ -17,7 +17,7 @@ function useScrollRestoration() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @deprecated
|
|
20
|
+
* @deprecated Use the `scrollRestoration` router option instead.
|
|
21
21
|
*/
|
|
22
22
|
export function ScrollRestoration(_props: ScrollRestorationOptions) {
|
|
23
23
|
useScrollRestoration()
|
package/src/awaited.tsx
CHANGED
|
@@ -7,6 +7,7 @@ export type AwaitOptions<T> = {
|
|
|
7
7
|
promise: Promise<T>
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/** Suspend until a deferred promise resolves/rejects and return its data. */
|
|
10
11
|
export function useAwaited<T>({
|
|
11
12
|
promise: _promise,
|
|
12
13
|
}: AwaitOptions<T>): [T, DeferredPromise<T>] {
|
|
@@ -23,6 +24,10 @@ export function useAwaited<T>({
|
|
|
23
24
|
return [promise[TSR_DEFERRED_PROMISE].data, promise]
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Component that suspends on a deferred promise and renders its child with
|
|
29
|
+
* the resolved value. Optionally provides a Suspense fallback.
|
|
30
|
+
*/
|
|
26
31
|
export function Await<T>(
|
|
27
32
|
props: AwaitOptions<T> & {
|
|
28
33
|
fallback?: React.ReactNode
|
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,
|
package/src/useLoaderData.tsx
CHANGED
|
@@ -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,
|
package/src/useLoaderDeps.tsx
CHANGED
|
@@ -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,
|
package/src/useLocation.tsx
CHANGED
|
@@ -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,
|
package/src/useNavigate.tsx
CHANGED
|
@@ -9,13 +9,17 @@ import type {
|
|
|
9
9
|
} from '@tanstack/router-core'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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`:
|
|
20
|
+
* - `from`: Optional route base used to resolve relative `to` paths.
|
|
17
21
|
*
|
|
18
|
-
* @returns A
|
|
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<
|