@tanstack/react-router 0.0.1-beta.151 → 0.0.1-beta.153
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/build/cjs/index.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +61 -61
- package/build/types/index.d.ts +24 -25
- package/build/umd/index.development.js +4 -2
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +79 -66
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.153",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
45
|
"@gisatcz/cross-package-react-context": "^0.2.0",
|
|
46
|
-
"@tanstack/
|
|
47
|
-
"@tanstack/
|
|
46
|
+
"@tanstack/react-store": "0.0.1-beta.153",
|
|
47
|
+
"@tanstack/router-core": "0.0.1-beta.153"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/index.tsx
CHANGED
|
@@ -6,15 +6,12 @@ import {
|
|
|
6
6
|
functionalUpdate,
|
|
7
7
|
last,
|
|
8
8
|
pick,
|
|
9
|
-
RegisteredRoutesInfo,
|
|
10
9
|
MatchRouteOptions,
|
|
11
10
|
RegisteredRouter,
|
|
12
11
|
RouterOptions,
|
|
13
12
|
Router,
|
|
14
13
|
RouteMatch,
|
|
15
14
|
RouteByPath,
|
|
16
|
-
AnyRoutesInfo,
|
|
17
|
-
DefaultRoutesInfo,
|
|
18
15
|
AnyRoute,
|
|
19
16
|
AnyRouteProps,
|
|
20
17
|
LinkOptions,
|
|
@@ -31,6 +28,13 @@ import {
|
|
|
31
28
|
UseLoaderResult,
|
|
32
29
|
ResolveFullSearchSchema,
|
|
33
30
|
Route,
|
|
31
|
+
RouteConstraints,
|
|
32
|
+
RoutePaths,
|
|
33
|
+
RoutesById,
|
|
34
|
+
RouteIds,
|
|
35
|
+
RouteById,
|
|
36
|
+
ParseRoute,
|
|
37
|
+
AllParams,
|
|
34
38
|
} from '@tanstack/router-core'
|
|
35
39
|
|
|
36
40
|
//
|
|
@@ -49,45 +53,42 @@ declare module '@tanstack/router-core' {
|
|
|
49
53
|
|
|
50
54
|
// Extend the Route class to have some React-Specific methods
|
|
51
55
|
interface Route<
|
|
52
|
-
TParentRoute extends
|
|
53
|
-
TPath extends
|
|
54
|
-
TFullPath extends
|
|
56
|
+
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
57
|
+
TPath extends RouteConstraints['TPath'] = '/',
|
|
58
|
+
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
55
59
|
TParentRoute,
|
|
56
60
|
TPath
|
|
57
61
|
>,
|
|
58
|
-
TCustomId extends
|
|
59
|
-
TId extends
|
|
62
|
+
TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
63
|
+
TId extends RouteConstraints['TId'] = ResolveId<
|
|
60
64
|
TParentRoute,
|
|
61
65
|
TCustomId,
|
|
62
66
|
TPath
|
|
63
67
|
>,
|
|
64
68
|
TLoader = unknown,
|
|
65
|
-
TSearchSchema extends
|
|
66
|
-
TFullSearchSchema extends
|
|
69
|
+
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
70
|
+
TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
67
71
|
TParentRoute,
|
|
68
72
|
TSearchSchema
|
|
69
73
|
>,
|
|
70
|
-
TParams extends
|
|
74
|
+
TParams extends RouteConstraints['TParams'] = Record<
|
|
71
75
|
ParsePathParams<TPath>,
|
|
72
76
|
string
|
|
73
77
|
>,
|
|
74
|
-
TAllParams extends MergeParamsFromParent<
|
|
78
|
+
TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<
|
|
75
79
|
TParentRoute['__types']['allParams'],
|
|
76
80
|
TParams
|
|
77
|
-
|
|
78
|
-
TParentContext extends
|
|
79
|
-
TAllParentContext extends
|
|
80
|
-
TRouteContext extends
|
|
81
|
-
TContext extends MergeParamsFromParent<
|
|
82
|
-
TParentRoute['__types']['context'],
|
|
83
|
-
TRouteContext
|
|
84
|
-
> = MergeParamsFromParent<
|
|
81
|
+
>,
|
|
82
|
+
TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],
|
|
83
|
+
TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'],
|
|
84
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
85
|
+
TContext extends RouteConstraints['TContext'] = MergeParamsFromParent<
|
|
85
86
|
TParentRoute['__types']['context'],
|
|
86
87
|
TRouteContext
|
|
87
88
|
>,
|
|
88
|
-
TRouterContext extends
|
|
89
|
-
TChildren extends
|
|
90
|
-
|
|
89
|
+
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
90
|
+
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
91
|
+
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
91
92
|
> {
|
|
92
93
|
useMatch: <TStrict extends boolean = true, TSelected = TContext>(opts?: {
|
|
93
94
|
strict?: TStrict
|
|
@@ -211,9 +212,9 @@ export function lazyRouteComponent<
|
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
export type LinkPropsOptions<
|
|
214
|
-
TFrom extends
|
|
215
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
215
216
|
TTo extends string = '',
|
|
216
|
-
> = LinkOptions<
|
|
217
|
+
> = LinkOptions<RegisteredRouter['routeTree'], TFrom, TTo> & {
|
|
217
218
|
// A function that returns additional props for the `active` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)
|
|
218
219
|
activeProps?:
|
|
219
220
|
| React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
@@ -227,20 +228,20 @@ export type LinkPropsOptions<
|
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
export type MakeUseMatchRouteOptions<
|
|
230
|
-
TFrom extends
|
|
231
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
231
232
|
TTo extends string = '',
|
|
232
|
-
> = ToOptions<
|
|
233
|
+
> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions
|
|
233
234
|
|
|
234
235
|
export type MakeMatchRouteOptions<
|
|
235
|
-
TFrom extends
|
|
236
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
236
237
|
TTo extends string = '',
|
|
237
|
-
> = ToOptions<
|
|
238
|
+
> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> &
|
|
238
239
|
MatchRouteOptions & {
|
|
239
240
|
// If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
|
|
240
241
|
children?:
|
|
241
242
|
| ((
|
|
242
243
|
params?: RouteByPath<
|
|
243
|
-
|
|
244
|
+
RegisteredRouter['routeTree'],
|
|
244
245
|
ResolveRelativePath<TFrom, NoInfer<TTo>>
|
|
245
246
|
>['__types']['allParams'],
|
|
246
247
|
) => ReactNode)
|
|
@@ -253,7 +254,7 @@ export type MakeLinkPropsOptions<
|
|
|
253
254
|
> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
254
255
|
|
|
255
256
|
export type MakeLinkOptions<
|
|
256
|
-
TFrom extends
|
|
257
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
257
258
|
TTo extends string = '',
|
|
258
259
|
> = LinkPropsOptions<TFrom, TTo> &
|
|
259
260
|
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
@@ -387,7 +388,7 @@ export function useLinkProps<
|
|
|
387
388
|
|
|
388
389
|
export interface LinkComponent<TProps extends Record<string, any> = {}> {
|
|
389
390
|
<
|
|
390
|
-
TFrom extends
|
|
391
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
391
392
|
TTo extends string = '',
|
|
392
393
|
>(
|
|
393
394
|
props: MakeLinkOptions<TFrom, TTo> &
|
|
@@ -416,9 +417,9 @@ export const Link: LinkComponent = React.forwardRef((props: any, ref) => {
|
|
|
416
417
|
}) as any
|
|
417
418
|
|
|
418
419
|
export function Navigate<
|
|
419
|
-
TFrom extends
|
|
420
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
420
421
|
TTo extends string = '',
|
|
421
|
-
>(props: NavigateOptions<
|
|
422
|
+
>(props: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>): null {
|
|
422
423
|
const router = useRouter()
|
|
423
424
|
|
|
424
425
|
React.useLayoutEffect(() => {
|
|
@@ -432,12 +433,11 @@ export const matchIdsContext = React.createContext<string[]>(null!)
|
|
|
432
433
|
export const routerContext = React.createContext<RegisteredRouter>(null!)
|
|
433
434
|
|
|
434
435
|
export type RouterProps<
|
|
435
|
-
|
|
436
|
-
TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
|
|
436
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
437
437
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
438
|
-
> = Omit<RouterOptions<
|
|
439
|
-
router: Router<
|
|
440
|
-
context?: Partial<RouterOptions<
|
|
438
|
+
> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
439
|
+
router: Router<TRouteTree>
|
|
440
|
+
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>
|
|
441
441
|
}
|
|
442
442
|
|
|
443
443
|
export function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
@@ -448,10 +448,9 @@ export function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
export function RouterProvider<
|
|
451
|
-
|
|
452
|
-
TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
|
|
451
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
453
452
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
454
|
-
>({ router, ...rest }: RouterProps<
|
|
453
|
+
>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {
|
|
455
454
|
router.update(rest)
|
|
456
455
|
|
|
457
456
|
React.useEffect(() => {
|
|
@@ -535,11 +534,11 @@ export function useMatches<T = RouteMatch[]>(opts?: {
|
|
|
535
534
|
}
|
|
536
535
|
|
|
537
536
|
export function useMatch<
|
|
538
|
-
TFrom extends
|
|
537
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
539
538
|
TStrict extends boolean = true,
|
|
540
539
|
TRouteMatchState = RouteMatch<
|
|
541
|
-
|
|
542
|
-
|
|
540
|
+
RegisteredRouter['routeTree'],
|
|
541
|
+
RouteById<RegisteredRouter['routeTree'], TFrom>
|
|
543
542
|
>,
|
|
544
543
|
TSelected = TRouteMatchState,
|
|
545
544
|
>(opts?: {
|
|
@@ -598,18 +597,23 @@ export function useMatch<
|
|
|
598
597
|
return match as any
|
|
599
598
|
}
|
|
600
599
|
|
|
601
|
-
export type RouteFromIdOrRoute<T> = T extends
|
|
600
|
+
export type RouteFromIdOrRoute<T> = T extends ParseRoute<
|
|
601
|
+
RegisteredRouter['routeTree']
|
|
602
|
+
>
|
|
602
603
|
? T
|
|
603
|
-
: T extends
|
|
604
|
-
?
|
|
604
|
+
: T extends RouteIds<RegisteredRouter['routeTree']>
|
|
605
|
+
? RoutesById<RegisteredRouter['routeTree']>[T]
|
|
605
606
|
: T extends string
|
|
606
|
-
?
|
|
607
|
+
? RouteIds<RegisteredRouter['routeTree']>
|
|
607
608
|
: never
|
|
608
609
|
|
|
609
610
|
export function useLoader<
|
|
610
|
-
TFrom extends
|
|
611
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
611
612
|
TStrict extends boolean = true,
|
|
612
|
-
TLoader =
|
|
613
|
+
TLoader = RouteById<
|
|
614
|
+
RegisteredRouter['routeTree'],
|
|
615
|
+
TFrom
|
|
616
|
+
>['__types']['loader'],
|
|
613
617
|
TSelected = TLoader,
|
|
614
618
|
>(opts?: {
|
|
615
619
|
from: TFrom
|
|
@@ -625,9 +629,12 @@ export function useLoader<
|
|
|
625
629
|
}
|
|
626
630
|
|
|
627
631
|
export function useRouterContext<
|
|
628
|
-
TFrom extends
|
|
632
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
629
633
|
TStrict extends boolean = true,
|
|
630
|
-
TContext =
|
|
634
|
+
TContext = RouteById<
|
|
635
|
+
RegisteredRouter['routeTree'],
|
|
636
|
+
TFrom
|
|
637
|
+
>['__types']['context'],
|
|
631
638
|
TSelected = TContext,
|
|
632
639
|
>(opts?: {
|
|
633
640
|
from: TFrom
|
|
@@ -642,9 +649,12 @@ export function useRouterContext<
|
|
|
642
649
|
}
|
|
643
650
|
|
|
644
651
|
export function useRouteContext<
|
|
645
|
-
TFrom extends
|
|
652
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
646
653
|
TStrict extends boolean = true,
|
|
647
|
-
TRouteContext =
|
|
654
|
+
TRouteContext = RouteById<
|
|
655
|
+
RegisteredRouter['routeTree'],
|
|
656
|
+
TFrom
|
|
657
|
+
>['__types']['routeContext'],
|
|
648
658
|
TSelected = TRouteContext,
|
|
649
659
|
>(opts?: {
|
|
650
660
|
from: TFrom
|
|
@@ -660,9 +670,12 @@ export function useRouteContext<
|
|
|
660
670
|
}
|
|
661
671
|
|
|
662
672
|
export function useSearch<
|
|
663
|
-
TFrom extends
|
|
673
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
664
674
|
TStrict extends boolean = true,
|
|
665
|
-
TSearch =
|
|
675
|
+
TSearch = RouteById<
|
|
676
|
+
RegisteredRouter['routeTree'],
|
|
677
|
+
TFrom
|
|
678
|
+
>['__types']['fullSearchSchema'],
|
|
666
679
|
TSelected = TSearch,
|
|
667
680
|
>(opts?: {
|
|
668
681
|
from: TFrom
|
|
@@ -679,9 +692,9 @@ export function useSearch<
|
|
|
679
692
|
}
|
|
680
693
|
|
|
681
694
|
export function useParams<
|
|
682
|
-
TFrom extends
|
|
683
|
-
TDefaultSelected =
|
|
684
|
-
|
|
695
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']> = '/',
|
|
696
|
+
TDefaultSelected = AllParams<RegisteredRouter['routeTree']> &
|
|
697
|
+
RouteById<RegisteredRouter['routeTree'], TFrom>['__types']['allParams'],
|
|
685
698
|
TSelected = TDefaultSelected,
|
|
686
699
|
>(opts?: {
|
|
687
700
|
from: TFrom
|
|
@@ -696,15 +709,15 @@ export function useParams<
|
|
|
696
709
|
}
|
|
697
710
|
|
|
698
711
|
export function useNavigate<
|
|
699
|
-
TDefaultFrom extends
|
|
712
|
+
TDefaultFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
700
713
|
>(defaultOpts?: { from?: TDefaultFrom }) {
|
|
701
714
|
const router = useRouter()
|
|
702
715
|
return React.useCallback(
|
|
703
716
|
<
|
|
704
|
-
TFrom extends
|
|
717
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = TDefaultFrom,
|
|
705
718
|
TTo extends string = '',
|
|
706
719
|
>(
|
|
707
|
-
opts?: NavigateOptions<
|
|
720
|
+
opts?: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>,
|
|
708
721
|
) => {
|
|
709
722
|
return router.navigate({ ...defaultOpts, ...(opts as any) })
|
|
710
723
|
},
|
|
@@ -843,10 +856,10 @@ function MatchInner({
|
|
|
843
856
|
return React.createElement(comp, {
|
|
844
857
|
useLoader: route.useLoader,
|
|
845
858
|
useMatch: route.useMatch,
|
|
846
|
-
useContext: route.useContext,
|
|
847
|
-
useRouteContext: route.useRouteContext,
|
|
859
|
+
useContext: route.useContext as any,
|
|
860
|
+
useRouteContext: route.useRouteContext as any,
|
|
848
861
|
useSearch: route.useSearch,
|
|
849
|
-
useParams: route.useParams,
|
|
862
|
+
useParams: route.useParams as any,
|
|
850
863
|
})
|
|
851
864
|
}
|
|
852
865
|
|