@tanstack/react-router 1.132.0-alpha.2 → 1.132.0-alpha.21
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/HeadContent.cjs +8 -6
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/ScriptOnce.cjs +1 -1
- package/dist/cjs/ScriptOnce.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -2
- package/dist/cjs/index.cjs +14 -14
- package/dist/cjs/index.d.cts +6 -3
- package/dist/cjs/link.cjs +63 -68
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +11 -11
- package/dist/cjs/scroll-restoration.cjs +11 -3
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/ssr/serializer.d.cts +6 -0
- package/dist/cjs/useBlocker.cjs +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +4 -11
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useParams.cjs +3 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/esm/HeadContent.js +8 -6
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/ScriptOnce.js +1 -1
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +5 -5
- package/dist/esm/link.js +63 -68
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +11 -11
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/scroll-restoration.js +11 -3
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/ssr/serializer.d.ts +6 -0
- package/dist/esm/useBlocker.js +1 -1
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.js +4 -11
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.js +3 -2
- package/dist/esm/useParams.js.map +1 -1
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +14 -7
- package/package.json +3 -3
- package/src/HeadContent.tsx +8 -6
- package/src/ScriptOnce.tsx +1 -1
- package/src/fileRoute.ts +10 -2
- package/src/index.tsx +10 -5
- package/src/link.tsx +66 -79
- package/src/route.tsx +74 -17
- package/src/scroll-restoration.tsx +11 -4
- package/src/ssr/serializer.ts +7 -0
- package/src/useBlocker.tsx +1 -1
- package/src/useNavigate.tsx +4 -18
- package/src/useParams.tsx +5 -3
package/src/route.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
ErrorComponentProps,
|
|
22
22
|
NotFoundError,
|
|
23
23
|
NotFoundRouteProps,
|
|
24
|
+
Register,
|
|
24
25
|
RegisteredRouter,
|
|
25
26
|
ResolveFullPath,
|
|
26
27
|
ResolveId,
|
|
@@ -158,6 +159,7 @@ export class RouteApi<
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
export class Route<
|
|
162
|
+
in out TRegister extends Register = Register,
|
|
161
163
|
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
162
164
|
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
163
165
|
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
@@ -179,8 +181,10 @@ export class Route<
|
|
|
179
181
|
in out TLoaderFn = undefined,
|
|
180
182
|
in out TChildren = unknown,
|
|
181
183
|
in out TFileRouteTypes = unknown,
|
|
184
|
+
in out TSSR = unknown,
|
|
182
185
|
>
|
|
183
186
|
extends BaseRoute<
|
|
187
|
+
TRegister,
|
|
184
188
|
TParentRoute,
|
|
185
189
|
TPath,
|
|
186
190
|
TFullPath,
|
|
@@ -194,10 +198,12 @@ export class Route<
|
|
|
194
198
|
TLoaderDeps,
|
|
195
199
|
TLoaderFn,
|
|
196
200
|
TChildren,
|
|
197
|
-
TFileRouteTypes
|
|
201
|
+
TFileRouteTypes,
|
|
202
|
+
TSSR
|
|
198
203
|
>
|
|
199
204
|
implements
|
|
200
205
|
RouteCore<
|
|
206
|
+
TRegister,
|
|
201
207
|
TParentRoute,
|
|
202
208
|
TPath,
|
|
203
209
|
TFullPath,
|
|
@@ -211,7 +217,8 @@ export class Route<
|
|
|
211
217
|
TLoaderDeps,
|
|
212
218
|
TLoaderFn,
|
|
213
219
|
TChildren,
|
|
214
|
-
TFileRouteTypes
|
|
220
|
+
TFileRouteTypes,
|
|
221
|
+
TSSR
|
|
215
222
|
>
|
|
216
223
|
{
|
|
217
224
|
/**
|
|
@@ -219,6 +226,7 @@ export class Route<
|
|
|
219
226
|
*/
|
|
220
227
|
constructor(
|
|
221
228
|
options?: RouteOptions<
|
|
229
|
+
TRegister,
|
|
222
230
|
TParentRoute,
|
|
223
231
|
TId,
|
|
224
232
|
TCustomId,
|
|
@@ -230,7 +238,8 @@ export class Route<
|
|
|
230
238
|
TLoaderFn,
|
|
231
239
|
TRouterContext,
|
|
232
240
|
TRouteContextFn,
|
|
233
|
-
TBeforeLoadFn
|
|
241
|
+
TBeforeLoadFn,
|
|
242
|
+
TSSR
|
|
234
243
|
>,
|
|
235
244
|
) {
|
|
236
245
|
super(options)
|
|
@@ -291,6 +300,7 @@ export class Route<
|
|
|
291
300
|
}
|
|
292
301
|
|
|
293
302
|
export function createRoute<
|
|
303
|
+
TRegister extends Register = Register,
|
|
294
304
|
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
295
305
|
TPath extends RouteConstraints['TPath'] = '/',
|
|
296
306
|
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
@@ -310,8 +320,10 @@ export function createRoute<
|
|
|
310
320
|
TLoaderDeps extends Record<string, any> = {},
|
|
311
321
|
TLoaderFn = undefined,
|
|
312
322
|
TChildren = unknown,
|
|
323
|
+
TSSR = unknown,
|
|
313
324
|
>(
|
|
314
325
|
options: RouteOptions<
|
|
326
|
+
TRegister,
|
|
315
327
|
TParentRoute,
|
|
316
328
|
TId,
|
|
317
329
|
TCustomId,
|
|
@@ -323,9 +335,11 @@ export function createRoute<
|
|
|
323
335
|
TLoaderFn,
|
|
324
336
|
AnyContext,
|
|
325
337
|
TRouteContextFn,
|
|
326
|
-
TBeforeLoadFn
|
|
338
|
+
TBeforeLoadFn,
|
|
339
|
+
TSSR
|
|
327
340
|
>,
|
|
328
341
|
): Route<
|
|
342
|
+
TRegister,
|
|
329
343
|
TParentRoute,
|
|
330
344
|
TPath,
|
|
331
345
|
TFullPath,
|
|
@@ -338,9 +352,11 @@ export function createRoute<
|
|
|
338
352
|
TBeforeLoadFn,
|
|
339
353
|
TLoaderDeps,
|
|
340
354
|
TLoaderFn,
|
|
341
|
-
TChildren
|
|
355
|
+
TChildren,
|
|
356
|
+
TSSR
|
|
342
357
|
> {
|
|
343
358
|
return new Route<
|
|
359
|
+
TRegister,
|
|
344
360
|
TParentRoute,
|
|
345
361
|
TPath,
|
|
346
362
|
TFullPath,
|
|
@@ -353,36 +369,53 @@ export function createRoute<
|
|
|
353
369
|
TBeforeLoadFn,
|
|
354
370
|
TLoaderDeps,
|
|
355
371
|
TLoaderFn,
|
|
356
|
-
TChildren
|
|
372
|
+
TChildren,
|
|
373
|
+
TSSR
|
|
357
374
|
>(options)
|
|
358
375
|
}
|
|
359
376
|
|
|
360
|
-
export type AnyRootRoute = RootRoute<
|
|
377
|
+
export type AnyRootRoute = RootRoute<
|
|
378
|
+
any,
|
|
379
|
+
any,
|
|
380
|
+
any,
|
|
381
|
+
any,
|
|
382
|
+
any,
|
|
383
|
+
any,
|
|
384
|
+
any,
|
|
385
|
+
any,
|
|
386
|
+
any
|
|
387
|
+
>
|
|
361
388
|
|
|
362
389
|
export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
363
390
|
return <
|
|
391
|
+
TRegister extends Register = Register,
|
|
364
392
|
TRouteContextFn = AnyContext,
|
|
365
393
|
TBeforeLoadFn = AnyContext,
|
|
366
394
|
TSearchValidator = undefined,
|
|
367
395
|
TLoaderDeps extends Record<string, any> = {},
|
|
368
396
|
TLoaderFn = undefined,
|
|
397
|
+
TSSR = unknown,
|
|
369
398
|
>(
|
|
370
399
|
options?: RootRouteOptions<
|
|
400
|
+
TRegister,
|
|
371
401
|
TSearchValidator,
|
|
372
402
|
TRouterContext,
|
|
373
403
|
TRouteContextFn,
|
|
374
404
|
TBeforeLoadFn,
|
|
375
405
|
TLoaderDeps,
|
|
376
|
-
TLoaderFn
|
|
406
|
+
TLoaderFn,
|
|
407
|
+
TSSR
|
|
377
408
|
>,
|
|
378
409
|
) => {
|
|
379
410
|
return createRootRoute<
|
|
411
|
+
TRegister,
|
|
380
412
|
TSearchValidator,
|
|
381
413
|
TRouterContext,
|
|
382
414
|
TRouteContextFn,
|
|
383
415
|
TBeforeLoadFn,
|
|
384
416
|
TLoaderDeps,
|
|
385
|
-
TLoaderFn
|
|
417
|
+
TLoaderFn,
|
|
418
|
+
TSSR
|
|
386
419
|
>(options as any)
|
|
387
420
|
}
|
|
388
421
|
}
|
|
@@ -393,6 +426,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
393
426
|
export const rootRouteWithContext = createRootRouteWithContext
|
|
394
427
|
|
|
395
428
|
export class RootRoute<
|
|
429
|
+
in out TRegister extends Register = Register,
|
|
396
430
|
in out TSearchValidator = undefined,
|
|
397
431
|
in out TRouterContext = {},
|
|
398
432
|
in out TRouteContextFn = AnyContext,
|
|
@@ -401,8 +435,10 @@ export class RootRoute<
|
|
|
401
435
|
in out TLoaderFn = undefined,
|
|
402
436
|
in out TChildren = unknown,
|
|
403
437
|
in out TFileRouteTypes = unknown,
|
|
438
|
+
in out TSSR = unknown,
|
|
404
439
|
>
|
|
405
440
|
extends BaseRootRoute<
|
|
441
|
+
TRegister,
|
|
406
442
|
TSearchValidator,
|
|
407
443
|
TRouterContext,
|
|
408
444
|
TRouteContextFn,
|
|
@@ -410,10 +446,12 @@ export class RootRoute<
|
|
|
410
446
|
TLoaderDeps,
|
|
411
447
|
TLoaderFn,
|
|
412
448
|
TChildren,
|
|
413
|
-
TFileRouteTypes
|
|
449
|
+
TFileRouteTypes,
|
|
450
|
+
TSSR
|
|
414
451
|
>
|
|
415
452
|
implements
|
|
416
453
|
RootRouteCore<
|
|
454
|
+
TRegister,
|
|
417
455
|
TSearchValidator,
|
|
418
456
|
TRouterContext,
|
|
419
457
|
TRouteContextFn,
|
|
@@ -421,7 +459,8 @@ export class RootRoute<
|
|
|
421
459
|
TLoaderDeps,
|
|
422
460
|
TLoaderFn,
|
|
423
461
|
TChildren,
|
|
424
|
-
TFileRouteTypes
|
|
462
|
+
TFileRouteTypes,
|
|
463
|
+
TSSR
|
|
425
464
|
>
|
|
426
465
|
{
|
|
427
466
|
/**
|
|
@@ -429,12 +468,14 @@ export class RootRoute<
|
|
|
429
468
|
*/
|
|
430
469
|
constructor(
|
|
431
470
|
options?: RootRouteOptions<
|
|
471
|
+
TRegister,
|
|
432
472
|
TSearchValidator,
|
|
433
473
|
TRouterContext,
|
|
434
474
|
TRouteContextFn,
|
|
435
475
|
TBeforeLoadFn,
|
|
436
476
|
TLoaderDeps,
|
|
437
|
-
TLoaderFn
|
|
477
|
+
TLoaderFn,
|
|
478
|
+
TSSR
|
|
438
479
|
>,
|
|
439
480
|
) {
|
|
440
481
|
super(options)
|
|
@@ -495,22 +536,27 @@ export class RootRoute<
|
|
|
495
536
|
}
|
|
496
537
|
|
|
497
538
|
export function createRootRoute<
|
|
539
|
+
TRegister extends Register = Register,
|
|
498
540
|
TSearchValidator = undefined,
|
|
499
541
|
TRouterContext = {},
|
|
500
542
|
TRouteContextFn = AnyContext,
|
|
501
543
|
TBeforeLoadFn = AnyContext,
|
|
502
544
|
TLoaderDeps extends Record<string, any> = {},
|
|
503
545
|
TLoaderFn = undefined,
|
|
546
|
+
TSSR = unknown,
|
|
504
547
|
>(
|
|
505
548
|
options?: RootRouteOptions<
|
|
549
|
+
TRegister,
|
|
506
550
|
TSearchValidator,
|
|
507
551
|
TRouterContext,
|
|
508
552
|
TRouteContextFn,
|
|
509
553
|
TBeforeLoadFn,
|
|
510
554
|
TLoaderDeps,
|
|
511
|
-
TLoaderFn
|
|
555
|
+
TLoaderFn,
|
|
556
|
+
TSSR
|
|
512
557
|
>,
|
|
513
558
|
): RootRoute<
|
|
559
|
+
TRegister,
|
|
514
560
|
TSearchValidator,
|
|
515
561
|
TRouterContext,
|
|
516
562
|
TRouteContextFn,
|
|
@@ -518,15 +564,20 @@ export function createRootRoute<
|
|
|
518
564
|
TLoaderDeps,
|
|
519
565
|
TLoaderFn,
|
|
520
566
|
unknown,
|
|
521
|
-
unknown
|
|
567
|
+
unknown,
|
|
568
|
+
TSSR
|
|
522
569
|
> {
|
|
523
570
|
return new RootRoute<
|
|
571
|
+
TRegister,
|
|
524
572
|
TSearchValidator,
|
|
525
573
|
TRouterContext,
|
|
526
574
|
TRouteContextFn,
|
|
527
575
|
TBeforeLoadFn,
|
|
528
576
|
TLoaderDeps,
|
|
529
|
-
TLoaderFn
|
|
577
|
+
TLoaderFn,
|
|
578
|
+
unknown,
|
|
579
|
+
unknown,
|
|
580
|
+
TSSR
|
|
530
581
|
>(options)
|
|
531
582
|
}
|
|
532
583
|
|
|
@@ -560,6 +611,7 @@ export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
|
|
|
560
611
|
export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']
|
|
561
612
|
|
|
562
613
|
export class NotFoundRoute<
|
|
614
|
+
TRegister extends Register,
|
|
563
615
|
TParentRoute extends AnyRootRoute,
|
|
564
616
|
TRouterContext = AnyContext,
|
|
565
617
|
TRouteContextFn = AnyContext,
|
|
@@ -568,7 +620,9 @@ export class NotFoundRoute<
|
|
|
568
620
|
TLoaderDeps extends Record<string, any> = {},
|
|
569
621
|
TLoaderFn = undefined,
|
|
570
622
|
TChildren = unknown,
|
|
623
|
+
TSSR = unknown,
|
|
571
624
|
> extends Route<
|
|
625
|
+
TRegister,
|
|
572
626
|
TParentRoute,
|
|
573
627
|
'/404',
|
|
574
628
|
'/404',
|
|
@@ -581,11 +635,13 @@ export class NotFoundRoute<
|
|
|
581
635
|
TBeforeLoadFn,
|
|
582
636
|
TLoaderDeps,
|
|
583
637
|
TLoaderFn,
|
|
584
|
-
TChildren
|
|
638
|
+
TChildren,
|
|
639
|
+
TSSR
|
|
585
640
|
> {
|
|
586
641
|
constructor(
|
|
587
642
|
options: Omit<
|
|
588
643
|
RouteOptions<
|
|
644
|
+
TRegister,
|
|
589
645
|
TParentRoute,
|
|
590
646
|
string,
|
|
591
647
|
string,
|
|
@@ -597,7 +653,8 @@ export class NotFoundRoute<
|
|
|
597
653
|
TLoaderFn,
|
|
598
654
|
TRouterContext,
|
|
599
655
|
TRouteContextFn,
|
|
600
|
-
TBeforeLoadFn
|
|
656
|
+
TBeforeLoadFn,
|
|
657
|
+
TSSR
|
|
601
658
|
>,
|
|
602
659
|
| 'caseSensitive'
|
|
603
660
|
| 'parseParams'
|
|
@@ -8,6 +8,17 @@ import { ScriptOnce } from './ScriptOnce'
|
|
|
8
8
|
|
|
9
9
|
export function ScrollRestoration() {
|
|
10
10
|
const router = useRouter()
|
|
11
|
+
if (!router.isScrollRestoring || !router.isServer) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
if (typeof router.options.scrollRestoration === 'function') {
|
|
15
|
+
const shouldRestore = router.options.scrollRestoration({
|
|
16
|
+
location: router.latestLocation,
|
|
17
|
+
})
|
|
18
|
+
if (!shouldRestore) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
const getKey =
|
|
12
23
|
router.options.getScrollRestorationKey || defaultGetScrollRestorationKey
|
|
13
24
|
const userKey = getKey(router.latestLocation)
|
|
@@ -16,10 +27,6 @@ export function ScrollRestoration() {
|
|
|
16
27
|
? userKey
|
|
17
28
|
: undefined
|
|
18
29
|
|
|
19
|
-
if (!router.isScrollRestoring || !router.isServer) {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
30
|
const restoreScrollOptions: Parameters<typeof restoreScroll>[0] = {
|
|
24
31
|
storageKey,
|
|
25
32
|
shouldScrollRestoration: true,
|
package/src/useBlocker.tsx
CHANGED
|
@@ -176,7 +176,7 @@ export function useBlocker(
|
|
|
176
176
|
function getLocation(
|
|
177
177
|
location: HistoryLocation,
|
|
178
178
|
): AnyShouldBlockFnLocation {
|
|
179
|
-
const parsedLocation = router.parseLocation(
|
|
179
|
+
const parsedLocation = router.parseLocation(location)
|
|
180
180
|
const matchedRoutes = router.getMatchedRoutes(
|
|
181
181
|
parsedLocation.pathname,
|
|
182
182
|
undefined,
|
package/src/useNavigate.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { useRouter } from './useRouter'
|
|
3
|
-
import { useMatch } from './useMatch'
|
|
4
3
|
import type {
|
|
5
4
|
AnyRouter,
|
|
6
5
|
FromPathOption,
|
|
@@ -15,29 +14,16 @@ export function useNavigate<
|
|
|
15
14
|
>(_defaultOpts?: {
|
|
16
15
|
from?: FromPathOption<TRouter, TDefaultFrom>
|
|
17
16
|
}): UseNavigateResult<TDefaultFrom> {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
// Just get the index of the current match to avoid rerenders
|
|
21
|
-
// as much as possible
|
|
22
|
-
const matchIndex = useMatch({
|
|
23
|
-
strict: false,
|
|
24
|
-
select: (match) => match.index,
|
|
25
|
-
})
|
|
17
|
+
const router = useRouter()
|
|
26
18
|
|
|
27
19
|
return React.useCallback(
|
|
28
20
|
(options: NavigateOptions) => {
|
|
29
|
-
|
|
30
|
-
options.from ??
|
|
31
|
-
_defaultOpts?.from ??
|
|
32
|
-
state.matches[matchIndex]!.fullPath
|
|
33
|
-
|
|
34
|
-
return navigate({
|
|
21
|
+
return router.navigate({
|
|
35
22
|
...options,
|
|
36
|
-
from,
|
|
23
|
+
from: options.from ?? _defaultOpts?.from,
|
|
37
24
|
})
|
|
38
25
|
},
|
|
39
|
-
|
|
40
|
-
[_defaultOpts?.from, navigate],
|
|
26
|
+
[_defaultOpts?.from, router],
|
|
41
27
|
) as UseNavigateResult<TDefaultFrom>
|
|
42
28
|
}
|
|
43
29
|
|
package/src/useParams.tsx
CHANGED
|
@@ -83,11 +83,13 @@ export function useParams<
|
|
|
83
83
|
> {
|
|
84
84
|
return useMatch({
|
|
85
85
|
from: opts.from!,
|
|
86
|
-
strict: opts.strict,
|
|
87
86
|
shouldThrow: opts.shouldThrow,
|
|
88
87
|
structuralSharing: opts.structuralSharing,
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
strict: opts.strict,
|
|
89
|
+
select: (match) => {
|
|
90
|
+
const params = opts.strict === false ? match.params : match._strictParams
|
|
91
|
+
|
|
92
|
+
return opts.select ? opts.select(params) : params
|
|
91
93
|
},
|
|
92
94
|
}) as any
|
|
93
95
|
}
|