@tanstack/react-router 0.0.1-beta.152 → 0.0.1-beta.154
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 -3
- 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 +62 -47
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.154",
|
|
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/router-core": "0.0.1-beta.154",
|
|
47
|
+
"@tanstack/react-store": "0.0.1-beta.154"
|
|
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,
|
|
@@ -32,6 +29,12 @@ import {
|
|
|
32
29
|
ResolveFullSearchSchema,
|
|
33
30
|
Route,
|
|
34
31
|
RouteConstraints,
|
|
32
|
+
RoutePaths,
|
|
33
|
+
RoutesById,
|
|
34
|
+
RouteIds,
|
|
35
|
+
RouteById,
|
|
36
|
+
ParseRoute,
|
|
37
|
+
AllParams,
|
|
35
38
|
} from '@tanstack/router-core'
|
|
36
39
|
|
|
37
40
|
//
|
|
@@ -85,7 +88,7 @@ declare module '@tanstack/router-core' {
|
|
|
85
88
|
>,
|
|
86
89
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
87
90
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
88
|
-
|
|
91
|
+
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
89
92
|
> {
|
|
90
93
|
useMatch: <TStrict extends boolean = true, TSelected = TContext>(opts?: {
|
|
91
94
|
strict?: TStrict
|
|
@@ -209,9 +212,9 @@ export function lazyRouteComponent<
|
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
export type LinkPropsOptions<
|
|
212
|
-
TFrom extends
|
|
215
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
213
216
|
TTo extends string = '',
|
|
214
|
-
> = LinkOptions<
|
|
217
|
+
> = LinkOptions<RegisteredRouter['routeTree'], TFrom, TTo> & {
|
|
215
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)
|
|
216
219
|
activeProps?:
|
|
217
220
|
| React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
@@ -225,20 +228,20 @@ export type LinkPropsOptions<
|
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
export type MakeUseMatchRouteOptions<
|
|
228
|
-
TFrom extends
|
|
231
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
229
232
|
TTo extends string = '',
|
|
230
|
-
> = ToOptions<
|
|
233
|
+
> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions
|
|
231
234
|
|
|
232
235
|
export type MakeMatchRouteOptions<
|
|
233
|
-
TFrom extends
|
|
236
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
234
237
|
TTo extends string = '',
|
|
235
|
-
> = ToOptions<
|
|
238
|
+
> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> &
|
|
236
239
|
MatchRouteOptions & {
|
|
237
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
|
|
238
241
|
children?:
|
|
239
242
|
| ((
|
|
240
243
|
params?: RouteByPath<
|
|
241
|
-
|
|
244
|
+
RegisteredRouter['routeTree'],
|
|
242
245
|
ResolveRelativePath<TFrom, NoInfer<TTo>>
|
|
243
246
|
>['__types']['allParams'],
|
|
244
247
|
) => ReactNode)
|
|
@@ -251,7 +254,7 @@ export type MakeLinkPropsOptions<
|
|
|
251
254
|
> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
252
255
|
|
|
253
256
|
export type MakeLinkOptions<
|
|
254
|
-
TFrom extends
|
|
257
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
255
258
|
TTo extends string = '',
|
|
256
259
|
> = LinkPropsOptions<TFrom, TTo> &
|
|
257
260
|
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
@@ -385,7 +388,7 @@ export function useLinkProps<
|
|
|
385
388
|
|
|
386
389
|
export interface LinkComponent<TProps extends Record<string, any> = {}> {
|
|
387
390
|
<
|
|
388
|
-
TFrom extends
|
|
391
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
389
392
|
TTo extends string = '',
|
|
390
393
|
>(
|
|
391
394
|
props: MakeLinkOptions<TFrom, TTo> &
|
|
@@ -414,9 +417,9 @@ export const Link: LinkComponent = React.forwardRef((props: any, ref) => {
|
|
|
414
417
|
}) as any
|
|
415
418
|
|
|
416
419
|
export function Navigate<
|
|
417
|
-
TFrom extends
|
|
420
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
418
421
|
TTo extends string = '',
|
|
419
|
-
>(props: NavigateOptions<
|
|
422
|
+
>(props: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>): null {
|
|
420
423
|
const router = useRouter()
|
|
421
424
|
|
|
422
425
|
React.useLayoutEffect(() => {
|
|
@@ -430,12 +433,11 @@ export const matchIdsContext = React.createContext<string[]>(null!)
|
|
|
430
433
|
export const routerContext = React.createContext<RegisteredRouter>(null!)
|
|
431
434
|
|
|
432
435
|
export type RouterProps<
|
|
433
|
-
|
|
434
|
-
TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
|
|
436
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
435
437
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
436
|
-
> = Omit<RouterOptions<
|
|
437
|
-
router: Router<
|
|
438
|
-
context?: Partial<RouterOptions<
|
|
438
|
+
> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
439
|
+
router: Router<TRouteTree>
|
|
440
|
+
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
export function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
@@ -446,10 +448,9 @@ export function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
|
446
448
|
}
|
|
447
449
|
|
|
448
450
|
export function RouterProvider<
|
|
449
|
-
|
|
450
|
-
TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
|
|
451
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
451
452
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
452
|
-
>({ router, ...rest }: RouterProps<
|
|
453
|
+
>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {
|
|
453
454
|
router.update(rest)
|
|
454
455
|
|
|
455
456
|
React.useEffect(() => {
|
|
@@ -533,11 +534,11 @@ export function useMatches<T = RouteMatch[]>(opts?: {
|
|
|
533
534
|
}
|
|
534
535
|
|
|
535
536
|
export function useMatch<
|
|
536
|
-
TFrom extends
|
|
537
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
537
538
|
TStrict extends boolean = true,
|
|
538
539
|
TRouteMatchState = RouteMatch<
|
|
539
|
-
|
|
540
|
-
|
|
540
|
+
RegisteredRouter['routeTree'],
|
|
541
|
+
RouteById<RegisteredRouter['routeTree'], TFrom>
|
|
541
542
|
>,
|
|
542
543
|
TSelected = TRouteMatchState,
|
|
543
544
|
>(opts?: {
|
|
@@ -596,18 +597,23 @@ export function useMatch<
|
|
|
596
597
|
return match as any
|
|
597
598
|
}
|
|
598
599
|
|
|
599
|
-
export type RouteFromIdOrRoute<T> = T extends
|
|
600
|
+
export type RouteFromIdOrRoute<T> = T extends ParseRoute<
|
|
601
|
+
RegisteredRouter['routeTree']
|
|
602
|
+
>
|
|
600
603
|
? T
|
|
601
|
-
: T extends
|
|
602
|
-
?
|
|
604
|
+
: T extends RouteIds<RegisteredRouter['routeTree']>
|
|
605
|
+
? RoutesById<RegisteredRouter['routeTree']>[T]
|
|
603
606
|
: T extends string
|
|
604
|
-
?
|
|
607
|
+
? RouteIds<RegisteredRouter['routeTree']>
|
|
605
608
|
: never
|
|
606
609
|
|
|
607
610
|
export function useLoader<
|
|
608
|
-
TFrom extends
|
|
611
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
609
612
|
TStrict extends boolean = true,
|
|
610
|
-
TLoader =
|
|
613
|
+
TLoader = RouteById<
|
|
614
|
+
RegisteredRouter['routeTree'],
|
|
615
|
+
TFrom
|
|
616
|
+
>['__types']['loader'],
|
|
611
617
|
TSelected = TLoader,
|
|
612
618
|
>(opts?: {
|
|
613
619
|
from: TFrom
|
|
@@ -623,9 +629,12 @@ export function useLoader<
|
|
|
623
629
|
}
|
|
624
630
|
|
|
625
631
|
export function useRouterContext<
|
|
626
|
-
TFrom extends
|
|
632
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
627
633
|
TStrict extends boolean = true,
|
|
628
|
-
TContext =
|
|
634
|
+
TContext = RouteById<
|
|
635
|
+
RegisteredRouter['routeTree'],
|
|
636
|
+
TFrom
|
|
637
|
+
>['__types']['context'],
|
|
629
638
|
TSelected = TContext,
|
|
630
639
|
>(opts?: {
|
|
631
640
|
from: TFrom
|
|
@@ -640,9 +649,12 @@ export function useRouterContext<
|
|
|
640
649
|
}
|
|
641
650
|
|
|
642
651
|
export function useRouteContext<
|
|
643
|
-
TFrom extends
|
|
652
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
644
653
|
TStrict extends boolean = true,
|
|
645
|
-
TRouteContext =
|
|
654
|
+
TRouteContext = RouteById<
|
|
655
|
+
RegisteredRouter['routeTree'],
|
|
656
|
+
TFrom
|
|
657
|
+
>['__types']['routeContext'],
|
|
646
658
|
TSelected = TRouteContext,
|
|
647
659
|
>(opts?: {
|
|
648
660
|
from: TFrom
|
|
@@ -658,9 +670,12 @@ export function useRouteContext<
|
|
|
658
670
|
}
|
|
659
671
|
|
|
660
672
|
export function useSearch<
|
|
661
|
-
TFrom extends
|
|
673
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']>,
|
|
662
674
|
TStrict extends boolean = true,
|
|
663
|
-
TSearch =
|
|
675
|
+
TSearch = RouteById<
|
|
676
|
+
RegisteredRouter['routeTree'],
|
|
677
|
+
TFrom
|
|
678
|
+
>['__types']['fullSearchSchema'],
|
|
664
679
|
TSelected = TSearch,
|
|
665
680
|
>(opts?: {
|
|
666
681
|
from: TFrom
|
|
@@ -677,9 +692,9 @@ export function useSearch<
|
|
|
677
692
|
}
|
|
678
693
|
|
|
679
694
|
export function useParams<
|
|
680
|
-
TFrom extends
|
|
681
|
-
TDefaultSelected =
|
|
682
|
-
|
|
695
|
+
TFrom extends RouteIds<RegisteredRouter['routeTree']> = '/',
|
|
696
|
+
TDefaultSelected = AllParams<RegisteredRouter['routeTree']> &
|
|
697
|
+
RouteById<RegisteredRouter['routeTree'], TFrom>['__types']['allParams'],
|
|
683
698
|
TSelected = TDefaultSelected,
|
|
684
699
|
>(opts?: {
|
|
685
700
|
from: TFrom
|
|
@@ -694,15 +709,15 @@ export function useParams<
|
|
|
694
709
|
}
|
|
695
710
|
|
|
696
711
|
export function useNavigate<
|
|
697
|
-
TDefaultFrom extends
|
|
712
|
+
TDefaultFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
|
|
698
713
|
>(defaultOpts?: { from?: TDefaultFrom }) {
|
|
699
714
|
const router = useRouter()
|
|
700
715
|
return React.useCallback(
|
|
701
716
|
<
|
|
702
|
-
TFrom extends
|
|
717
|
+
TFrom extends RoutePaths<RegisteredRouter['routeTree']> = TDefaultFrom,
|
|
703
718
|
TTo extends string = '',
|
|
704
719
|
>(
|
|
705
|
-
opts?: NavigateOptions<
|
|
720
|
+
opts?: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>,
|
|
706
721
|
) => {
|
|
707
722
|
return router.navigate({ ...defaultOpts, ...(opts as any) })
|
|
708
723
|
},
|
|
@@ -841,10 +856,10 @@ function MatchInner({
|
|
|
841
856
|
return React.createElement(comp, {
|
|
842
857
|
useLoader: route.useLoader,
|
|
843
858
|
useMatch: route.useMatch,
|
|
844
|
-
useContext: route.useContext,
|
|
845
|
-
useRouteContext: route.useRouteContext,
|
|
859
|
+
useContext: route.useContext as any,
|
|
860
|
+
useRouteContext: route.useRouteContext as any,
|
|
846
861
|
useSearch: route.useSearch,
|
|
847
|
-
useParams: route.useParams,
|
|
862
|
+
useParams: route.useParams as any,
|
|
848
863
|
})
|
|
849
864
|
}
|
|
850
865
|
|