@tanstack/react-router 1.121.0-alpha.3 → 1.121.0
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/ClientOnly.cjs.map +1 -1
- package/dist/cjs/ClientOnly.d.cts +1 -1
- package/dist/cjs/link.cjs +17 -18
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +2 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +3 -3
- package/dist/cjs/useNavigate.cjs +1 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/esm/ClientOnly.d.ts +1 -1
- package/dist/esm/ClientOnly.js.map +1 -1
- package/dist/esm/link.d.ts +2 -2
- package/dist/esm/link.js +17 -18
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +3 -3
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/useNavigate.js +1 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/api.d.ts +2 -0
- package/dist/llms/rules/api.js +4241 -0
- package/dist/llms/rules/guide.d.ts +2 -0
- package/dist/llms/rules/guide.js +6225 -0
- package/dist/llms/rules/routing.d.ts +2 -0
- package/dist/llms/rules/routing.js +1951 -0
- package/dist/llms/rules/setup-and-architecture.d.ts +2 -0
- package/dist/llms/rules/setup-and-architecture.js +933 -0
- package/package.json +11 -4
- package/src/ClientOnly.tsx +1 -1
- package/src/link.tsx +20 -28
- package/src/route.tsx +87 -53
- package/src/useNavigate.tsx +2 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.121.0
|
|
3
|
+
"version": "1.121.0",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,13 @@
|
|
|
38
38
|
"default": "./dist/cjs/index.cjs"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
"./package.json": "./package.json"
|
|
41
|
+
"./package.json": "./package.json",
|
|
42
|
+
"./llms": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/llms/index.d.ts",
|
|
45
|
+
"default": "./dist/llms/index.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
42
48
|
},
|
|
43
49
|
"sideEffects": false,
|
|
44
50
|
"files": [
|
|
@@ -53,8 +59,8 @@
|
|
|
53
59
|
"jsesc": "^3.1.0",
|
|
54
60
|
"tiny-invariant": "^1.3.3",
|
|
55
61
|
"tiny-warning": "^1.0.3",
|
|
56
|
-
"@tanstack/history": "1.
|
|
57
|
-
"@tanstack/router-core": "1.121.0
|
|
62
|
+
"@tanstack/history": "1.120.17",
|
|
63
|
+
"@tanstack/router-core": "1.121.0"
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
60
66
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -64,6 +70,7 @@
|
|
|
64
70
|
"combinate": "^1.1.11",
|
|
65
71
|
"react": "^19.0.0",
|
|
66
72
|
"react-dom": "^19.0.0",
|
|
73
|
+
"vibe-rules": "^0.2.57",
|
|
67
74
|
"zod": "^3.24.2"
|
|
68
75
|
},
|
|
69
76
|
"peerDependencies": {
|
package/src/ClientOnly.tsx
CHANGED
package/src/link.tsx
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
} from './utils'
|
|
18
18
|
|
|
19
19
|
import { useMatch } from './useMatch'
|
|
20
|
-
import { useMatches } from './Matches'
|
|
21
20
|
import type {
|
|
22
21
|
AnyRouter,
|
|
23
22
|
Constrain,
|
|
@@ -106,39 +105,28 @@ export function useLinkProps<
|
|
|
106
105
|
structuralSharing: true as any,
|
|
107
106
|
})
|
|
108
107
|
|
|
109
|
-
const isRelativeFromPath = options.relative === 'path'
|
|
110
|
-
|
|
111
|
-
// when `from` is not supplied, use the nearest parent match's full path as the `from` location
|
|
112
|
-
// so relative routing works as expected. Try to stay out of rerenders as much as possible.
|
|
113
108
|
const nearestFrom = useMatch({
|
|
114
109
|
strict: false,
|
|
115
|
-
select: (match) =>
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
// When no from and relative is path, use the leaf match as the from location
|
|
119
|
-
// Avoid rerenders as much as possible.
|
|
120
|
-
const leafFrom = useMatches({
|
|
121
|
-
select: (matches) =>
|
|
122
|
-
isRelativeFromPath ? matches[matches.length - 1]!.fullPath : undefined,
|
|
110
|
+
select: (match) => match.fullPath,
|
|
123
111
|
})
|
|
124
112
|
|
|
125
|
-
const from = options.from ??
|
|
113
|
+
const from = options.from ?? nearestFrom
|
|
126
114
|
|
|
127
115
|
// Use it as the default `from` location
|
|
128
|
-
|
|
116
|
+
options = { ...options, from }
|
|
129
117
|
|
|
130
118
|
const next = React.useMemo(
|
|
131
|
-
() => router.buildLocation(
|
|
119
|
+
() => router.buildLocation(options as any),
|
|
132
120
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
|
-
[router,
|
|
121
|
+
[router, options, currentSearch],
|
|
134
122
|
)
|
|
135
123
|
|
|
136
124
|
const preload = React.useMemo(() => {
|
|
137
|
-
if (
|
|
125
|
+
if (options.reloadDocument) {
|
|
138
126
|
return false
|
|
139
127
|
}
|
|
140
128
|
return userPreload ?? router.options.defaultPreload
|
|
141
|
-
}, [router.options.defaultPreload, userPreload,
|
|
129
|
+
}, [router.options.defaultPreload, userPreload, options.reloadDocument])
|
|
142
130
|
const preloadDelay =
|
|
143
131
|
userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0
|
|
144
132
|
|
|
@@ -189,11 +177,11 @@ export function useLinkProps<
|
|
|
189
177
|
})
|
|
190
178
|
|
|
191
179
|
const doPreload = React.useCallback(() => {
|
|
192
|
-
router.preloadRoute(
|
|
180
|
+
router.preloadRoute(options as any).catch((err) => {
|
|
193
181
|
console.warn(err)
|
|
194
182
|
console.warn(preloadWarning)
|
|
195
183
|
})
|
|
196
|
-
}, [
|
|
184
|
+
}, [options, router])
|
|
197
185
|
|
|
198
186
|
const preloadViewportIoCallback = React.useCallback(
|
|
199
187
|
(entry: IntersectionObserverEntry | undefined) => {
|
|
@@ -263,14 +251,14 @@ export function useLinkProps<
|
|
|
263
251
|
// All is well? Navigate!
|
|
264
252
|
// N.B. we don't call `router.commitLocation(next) here because we want to run `validateSearch` before committing
|
|
265
253
|
return router.navigate({
|
|
266
|
-
...
|
|
254
|
+
...options,
|
|
267
255
|
replace,
|
|
268
256
|
resetScroll,
|
|
269
257
|
hashScrollIntoView,
|
|
270
258
|
startTransition,
|
|
271
259
|
viewTransition,
|
|
272
260
|
ignoreBlocker,
|
|
273
|
-
}
|
|
261
|
+
})
|
|
274
262
|
}
|
|
275
263
|
}
|
|
276
264
|
|
|
@@ -293,10 +281,14 @@ export function useLinkProps<
|
|
|
293
281
|
return
|
|
294
282
|
}
|
|
295
283
|
|
|
296
|
-
|
|
297
|
-
eventTarget.preloadTimeout = null
|
|
284
|
+
if (!preloadDelay) {
|
|
298
285
|
doPreload()
|
|
299
|
-
}
|
|
286
|
+
} else {
|
|
287
|
+
eventTarget.preloadTimeout = setTimeout(() => {
|
|
288
|
+
eventTarget.preloadTimeout = null
|
|
289
|
+
doPreload()
|
|
290
|
+
}, preloadDelay)
|
|
291
|
+
}
|
|
300
292
|
}
|
|
301
293
|
}
|
|
302
294
|
|
|
@@ -378,8 +370,8 @@ type UseLinkReactProps<TComp> = TComp extends keyof React.JSX.IntrinsicElements
|
|
|
378
370
|
> &
|
|
379
371
|
React.RefAttributes<
|
|
380
372
|
TComp extends
|
|
381
|
-
| React.FC<{ ref: infer TRef }>
|
|
382
|
-
| React.Component<{ ref: infer TRef }>
|
|
373
|
+
| React.FC<{ ref: React.Ref<infer TRef> }>
|
|
374
|
+
| React.Component<{ ref: React.Ref<infer TRef> }>
|
|
383
375
|
? TRef
|
|
384
376
|
: never
|
|
385
377
|
>
|
package/src/route.tsx
CHANGED
|
@@ -25,9 +25,11 @@ import type {
|
|
|
25
25
|
ResolveFullPath,
|
|
26
26
|
ResolveId,
|
|
27
27
|
ResolveParams,
|
|
28
|
+
RootRoute as RootRouteCore,
|
|
28
29
|
RootRouteId,
|
|
29
30
|
RootRouteOptions,
|
|
30
31
|
RouteConstraints,
|
|
32
|
+
Route as RouteCore,
|
|
31
33
|
RouteIds,
|
|
32
34
|
RouteMask,
|
|
33
35
|
RouteOptions,
|
|
@@ -148,43 +150,62 @@ export class RouteApi<
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
export class Route<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
154
|
+
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
155
|
+
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
156
|
+
TParentRoute,
|
|
157
|
+
TPath
|
|
158
|
+
>,
|
|
159
|
+
in out TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
160
|
+
in out TId extends RouteConstraints['TId'] = ResolveId<
|
|
161
|
+
TParentRoute,
|
|
162
|
+
TCustomId,
|
|
163
|
+
TPath
|
|
164
|
+
>,
|
|
165
|
+
in out TSearchValidator = undefined,
|
|
166
|
+
in out TParams = ResolveParams<TPath>,
|
|
167
|
+
in out TRouterContext = AnyContext,
|
|
168
|
+
in out TRouteContextFn = AnyContext,
|
|
169
|
+
in out TBeforeLoadFn = AnyContext,
|
|
170
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
171
|
+
in out TLoaderFn = undefined,
|
|
172
|
+
in out TChildren = unknown,
|
|
173
|
+
in out TFileRouteTypes = unknown,
|
|
174
|
+
>
|
|
175
|
+
extends BaseRoute<
|
|
159
176
|
TParentRoute,
|
|
177
|
+
TPath,
|
|
178
|
+
TFullPath,
|
|
160
179
|
TCustomId,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
180
|
+
TId,
|
|
181
|
+
TSearchValidator,
|
|
182
|
+
TParams,
|
|
183
|
+
TRouterContext,
|
|
184
|
+
TRouteContextFn,
|
|
185
|
+
TBeforeLoadFn,
|
|
186
|
+
TLoaderDeps,
|
|
187
|
+
TLoaderFn,
|
|
188
|
+
TChildren,
|
|
189
|
+
TFileRouteTypes
|
|
190
|
+
>
|
|
191
|
+
implements
|
|
192
|
+
RouteCore<
|
|
193
|
+
TParentRoute,
|
|
194
|
+
TPath,
|
|
195
|
+
TFullPath,
|
|
196
|
+
TCustomId,
|
|
197
|
+
TId,
|
|
198
|
+
TSearchValidator,
|
|
199
|
+
TParams,
|
|
200
|
+
TRouterContext,
|
|
201
|
+
TRouteContextFn,
|
|
202
|
+
TBeforeLoadFn,
|
|
203
|
+
TLoaderDeps,
|
|
204
|
+
TLoaderFn,
|
|
205
|
+
TChildren,
|
|
206
|
+
TFileRouteTypes
|
|
207
|
+
>
|
|
208
|
+
{
|
|
188
209
|
/**
|
|
189
210
|
* @deprecated Use the `createRoute` function instead.
|
|
190
211
|
*/
|
|
@@ -364,24 +385,37 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
364
385
|
export const rootRouteWithContext = createRootRouteWithContext
|
|
365
386
|
|
|
366
387
|
export class RootRoute<
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
>
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
388
|
+
in out TSearchValidator = undefined,
|
|
389
|
+
in out TRouterContext = {},
|
|
390
|
+
in out TRouteContextFn = AnyContext,
|
|
391
|
+
in out TBeforeLoadFn = AnyContext,
|
|
392
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
393
|
+
in out TLoaderFn = undefined,
|
|
394
|
+
in out TChildren = unknown,
|
|
395
|
+
in out TFileRouteTypes = unknown,
|
|
396
|
+
>
|
|
397
|
+
extends BaseRootRoute<
|
|
398
|
+
TSearchValidator,
|
|
399
|
+
TRouterContext,
|
|
400
|
+
TRouteContextFn,
|
|
401
|
+
TBeforeLoadFn,
|
|
402
|
+
TLoaderDeps,
|
|
403
|
+
TLoaderFn,
|
|
404
|
+
TChildren,
|
|
405
|
+
TFileRouteTypes
|
|
406
|
+
>
|
|
407
|
+
implements
|
|
408
|
+
RootRouteCore<
|
|
409
|
+
TSearchValidator,
|
|
410
|
+
TRouterContext,
|
|
411
|
+
TRouteContextFn,
|
|
412
|
+
TBeforeLoadFn,
|
|
413
|
+
TLoaderDeps,
|
|
414
|
+
TLoaderFn,
|
|
415
|
+
TChildren,
|
|
416
|
+
TFileRouteTypes
|
|
417
|
+
>
|
|
418
|
+
{
|
|
385
419
|
/**
|
|
386
420
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
387
421
|
*/
|
package/src/useNavigate.tsx
CHANGED
|
@@ -26,18 +26,14 @@ export function useNavigate<
|
|
|
26
26
|
|
|
27
27
|
return React.useCallback(
|
|
28
28
|
(options: NavigateOptions) => {
|
|
29
|
-
const isRelativeFromPath = options.relative === 'path'
|
|
30
|
-
|
|
31
29
|
const from =
|
|
32
30
|
options.from ??
|
|
33
31
|
_defaultOpts?.from ??
|
|
34
|
-
|
|
35
|
-
? state.matches[state.matches.length - 1]!.fullPath
|
|
36
|
-
: state.matches[matchIndex]!.fullPath)
|
|
32
|
+
state.matches[matchIndex]!.fullPath
|
|
37
33
|
|
|
38
34
|
return navigate({
|
|
39
35
|
...options,
|
|
40
|
-
from
|
|
36
|
+
from,
|
|
41
37
|
})
|
|
42
38
|
},
|
|
43
39
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|