@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/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.151",
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/router-core": "0.0.1-beta.151",
47
- "@tanstack/react-store": "0.0.1-beta.151"
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 AnyRoute = AnyRoute,
53
- TPath extends string = '/',
54
- TFullPath extends ResolveFullPath<TParentRoute, TPath> = ResolveFullPath<
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 string = string,
59
- TId extends ResolveId<TParentRoute, TCustomId, TPath> = ResolveId<
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 AnySearchSchema = {},
66
- TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<
69
+ TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
70
+ TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
67
71
  TParentRoute,
68
72
  TSearchSchema
69
73
  >,
70
- TParams extends Record<ParsePathParams<TPath>, any> = Record<
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
- > = MergeParamsFromParent<TParentRoute['__types']['allParams'], TParams>,
78
- TParentContext extends TParentRoute['__types']['routeContext'] = TParentRoute['__types']['routeContext'],
79
- TAllParentContext extends TParentRoute['__types']['context'] = TParentRoute['__types']['context'],
80
- TRouteContext extends RouteContext = RouteContext,
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 AnyContext = AnyContext,
89
- TChildren extends unknown = unknown,
90
- TRoutesInfo extends DefaultRoutesInfo = DefaultRoutesInfo,
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 RegisteredRoutesInfo['routePaths'] = '/',
215
+ TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
215
216
  TTo extends string = '',
216
- > = LinkOptions<RegisteredRoutesInfo, TFrom, TTo> & {
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 RegisteredRoutesInfo['routePaths'] = '/',
231
+ TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
231
232
  TTo extends string = '',
232
- > = ToOptions<RegisteredRoutesInfo, TFrom, TTo> & MatchRouteOptions
233
+ > = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions
233
234
 
234
235
  export type MakeMatchRouteOptions<
235
- TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
236
+ TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
236
237
  TTo extends string = '',
237
- > = ToOptions<RegisteredRoutesInfo, TFrom, TTo> &
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
- RegisteredRoutesInfo,
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 RegisteredRoutesInfo['routePaths'] = '/',
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 RegisteredRoutesInfo['routePaths'] = '/',
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 RegisteredRoutesInfo['routePaths'] = '/',
420
+ TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/',
420
421
  TTo extends string = '',
421
- >(props: NavigateOptions<RegisteredRoutesInfo, TFrom, TTo>): null {
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
- TRouteConfig extends AnyRoute = AnyRoute,
436
- TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
436
+ TRouteTree extends AnyRoute = AnyRoute,
437
437
  TDehydrated extends Record<string, any> = Record<string, any>,
438
- > = Omit<RouterOptions<TRouteConfig, TDehydrated>, 'context'> & {
439
- router: Router<TRouteConfig, TRoutesInfo>
440
- context?: Partial<RouterOptions<TRouteConfig, TDehydrated>['context']>
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
- TRouteConfig extends AnyRoute = AnyRoute,
452
- TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo,
451
+ TRouteTree extends AnyRoute = AnyRoute,
453
452
  TDehydrated extends Record<string, any> = Record<string, any>,
454
- >({ router, ...rest }: RouterProps<TRouteConfig, TRoutesInfo, TDehydrated>) {
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 keyof RegisteredRoutesInfo['routesById'],
537
+ TFrom extends RouteIds<RegisteredRouter['routeTree']>,
539
538
  TStrict extends boolean = true,
540
539
  TRouteMatchState = RouteMatch<
541
- RegisteredRoutesInfo,
542
- RegisteredRoutesInfo['routesById'][TFrom]
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 RegisteredRoutesInfo['routeUnion']
600
+ export type RouteFromIdOrRoute<T> = T extends ParseRoute<
601
+ RegisteredRouter['routeTree']
602
+ >
602
603
  ? T
603
- : T extends keyof RegisteredRoutesInfo['routesById']
604
- ? RegisteredRoutesInfo['routesById'][T]
604
+ : T extends RouteIds<RegisteredRouter['routeTree']>
605
+ ? RoutesById<RegisteredRouter['routeTree']>[T]
605
606
  : T extends string
606
- ? keyof RegisteredRoutesInfo['routesById']
607
+ ? RouteIds<RegisteredRouter['routeTree']>
607
608
  : never
608
609
 
609
610
  export function useLoader<
610
- TFrom extends keyof RegisteredRoutesInfo['routesById'],
611
+ TFrom extends RouteIds<RegisteredRouter['routeTree']>,
611
612
  TStrict extends boolean = true,
612
- TLoader = RegisteredRoutesInfo['routesById'][TFrom]['__types']['loader'],
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 keyof RegisteredRoutesInfo['routesById'],
632
+ TFrom extends RouteIds<RegisteredRouter['routeTree']>,
629
633
  TStrict extends boolean = true,
630
- TContext = RegisteredRoutesInfo['routesById'][TFrom]['__types']['context'],
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 keyof RegisteredRoutesInfo['routesById'],
652
+ TFrom extends RouteIds<RegisteredRouter['routeTree']>,
646
653
  TStrict extends boolean = true,
647
- TRouteContext = RegisteredRoutesInfo['routesById'][TFrom]['__types']['routeContext'],
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 keyof RegisteredRoutesInfo['routesById'],
673
+ TFrom extends RouteIds<RegisteredRouter['routeTree']>,
664
674
  TStrict extends boolean = true,
665
- TSearch = RegisteredRoutesInfo['routesById'][TFrom]['__types']['fullSearchSchema'],
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 keyof RegisteredRoutesInfo['routesById'] = '/',
683
- TDefaultSelected = RegisteredRoutesInfo['allParams'] &
684
- RegisteredRoutesInfo['routesById'][TFrom]['__types']['allParams'],
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 RegisteredRoutesInfo['routePaths'] = '/',
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 RegisteredRoutesInfo['routePaths'] = TDefaultFrom,
717
+ TFrom extends RoutePaths<RegisteredRouter['routeTree']> = TDefaultFrom,
705
718
  TTo extends string = '',
706
719
  >(
707
- opts?: NavigateOptions<RegisteredRoutesInfo, TFrom, TTo>,
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