@tanstack/react-router 0.0.1-beta.274 → 0.0.1-beta.276
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/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/redirects.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +14 -6
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +14 -6
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +351 -351
- package/build/types/Matches.d.ts +2 -1
- package/build/types/RouterProvider.d.ts +2 -2
- package/build/types/fileRoute.d.ts +2 -2
- package/build/types/redirects.d.ts +1 -1
- package/build/types/route.d.ts +23 -23
- package/build/types/routeInfo.d.ts +1 -1
- package/build/types/router.d.ts +2 -1
- package/build/umd/index.development.js +14 -6
- 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 +2 -2
- package/src/Matches.tsx +2 -1
- package/src/RouterProvider.tsx +1 -1
- package/src/fileRoute.ts +3 -0
- package/src/redirects.ts +1 -1
- package/src/route.ts +30 -19
- package/src/routeInfo.ts +2 -0
- package/src/router.ts +19 -9
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.276",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "0.0.1-beta.
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.276"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -43,9 +43,10 @@ export interface RouteMatch<
|
|
|
43
43
|
shouldReloadDeps: any
|
|
44
44
|
abortController: AbortController
|
|
45
45
|
cause: 'preload' | 'enter' | 'stay'
|
|
46
|
+
loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export type AnyRouteMatch = RouteMatch<any>
|
|
49
|
+
export type AnyRouteMatch = RouteMatch<any, any>
|
|
49
50
|
|
|
50
51
|
export function Matches() {
|
|
51
52
|
const router = useRouter()
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -49,7 +49,7 @@ export type MatchRouteFn<TRouteTree extends AnyRoute> = <
|
|
|
49
49
|
) => false | RouteById<TRouteTree, TResolved>['types']['allParams']
|
|
50
50
|
|
|
51
51
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (
|
|
52
|
-
opts:
|
|
52
|
+
opts: ToOptions<TRouteTree>,
|
|
53
53
|
) => ParsedLocation
|
|
54
54
|
|
|
55
55
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string)
|
package/src/fileRoute.ts
CHANGED
|
@@ -105,6 +105,7 @@ export class FileRoute<
|
|
|
105
105
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
106
106
|
>,
|
|
107
107
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
108
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
108
109
|
TLoaderData extends any = unknown,
|
|
109
110
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
110
111
|
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
@@ -120,6 +121,7 @@ export class FileRoute<
|
|
|
120
121
|
TAllParams,
|
|
121
122
|
TRouteContext,
|
|
122
123
|
TContext,
|
|
124
|
+
TLoaderDeps,
|
|
123
125
|
TLoaderData
|
|
124
126
|
>,
|
|
125
127
|
'getParentRoute' | 'path' | 'id'
|
|
@@ -138,6 +140,7 @@ export class FileRoute<
|
|
|
138
140
|
TRouteContext,
|
|
139
141
|
TContext,
|
|
140
142
|
TRouterContext,
|
|
143
|
+
TLoaderDeps,
|
|
141
144
|
TLoaderData,
|
|
142
145
|
TChildren,
|
|
143
146
|
TRouteTree
|
package/src/redirects.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { RegisteredRouter } from './router'
|
|
|
5
5
|
|
|
6
6
|
// Detect if we're in the DOM
|
|
7
7
|
|
|
8
|
-
export type AnyRedirect = Redirect<any, any, any>
|
|
8
|
+
export type AnyRedirect = Redirect<any, any, any, any, any>
|
|
9
9
|
|
|
10
10
|
export type Redirect<
|
|
11
11
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
package/src/route.ts
CHANGED
|
@@ -62,6 +62,7 @@ export type RouteOptions<
|
|
|
62
62
|
TAllParams extends AnyPathParams = TParams,
|
|
63
63
|
TRouteContext extends RouteContext = RouteContext,
|
|
64
64
|
TAllContext extends Record<string, any> = AnyContext,
|
|
65
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
65
66
|
TLoaderData extends any = unknown,
|
|
66
67
|
> = BaseRouteOptions<
|
|
67
68
|
TParentRoute,
|
|
@@ -73,6 +74,7 @@ export type RouteOptions<
|
|
|
73
74
|
TAllParams,
|
|
74
75
|
TRouteContext,
|
|
75
76
|
TAllContext,
|
|
77
|
+
TLoaderDeps,
|
|
76
78
|
TLoaderData
|
|
77
79
|
> &
|
|
78
80
|
UpdatableRouteOptions<NoInfer<TFullSearchSchema>>
|
|
@@ -82,10 +84,6 @@ export type ParamsFallback<
|
|
|
82
84
|
TParams,
|
|
83
85
|
> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams
|
|
84
86
|
|
|
85
|
-
type Prefix<T extends string, U extends string> = U extends `${T}${infer _}`
|
|
86
|
-
? U
|
|
87
|
-
: never
|
|
88
|
-
|
|
89
87
|
export type BaseRouteOptions<
|
|
90
88
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
91
89
|
TCustomId extends string = string,
|
|
@@ -96,6 +94,7 @@ export type BaseRouteOptions<
|
|
|
96
94
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
97
95
|
TRouteContext extends RouteContext = RouteContext,
|
|
98
96
|
TAllContext extends Record<string, any> = AnyContext,
|
|
97
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
99
98
|
TLoaderData extends any = unknown,
|
|
100
99
|
> = RoutePathOptions<TCustomId, TPath> & {
|
|
101
100
|
getParentRoute: () => TParentRoute
|
|
@@ -131,10 +130,10 @@ export type BaseRouteOptions<
|
|
|
131
130
|
TRouteContext
|
|
132
131
|
>
|
|
133
132
|
}) & {
|
|
134
|
-
|
|
133
|
+
loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps
|
|
135
134
|
loader?: RouteLoaderFn<
|
|
136
135
|
TAllParams,
|
|
137
|
-
|
|
136
|
+
NoInfer<TLoaderDeps>,
|
|
138
137
|
NoInfer<TAllContext>,
|
|
139
138
|
NoInfer<TRouteContext>,
|
|
140
139
|
TLoaderData
|
|
@@ -170,7 +169,7 @@ type BeforeLoadFn<
|
|
|
170
169
|
context: TParentRoute['types']['allContext']
|
|
171
170
|
location: ParsedLocation
|
|
172
171
|
navigate: NavigateFn<AnyRoute>
|
|
173
|
-
buildLocation: BuildLocationFn<
|
|
172
|
+
buildLocation: BuildLocationFn<TParentRoute>
|
|
174
173
|
cause: 'preload' | 'enter' | 'stay'
|
|
175
174
|
}) => Promise<TRouteContext> | TRouteContext | void
|
|
176
175
|
|
|
@@ -241,31 +240,26 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
|
|
|
241
240
|
|
|
242
241
|
export type RouteLoaderFn<
|
|
243
242
|
TAllParams = {},
|
|
244
|
-
|
|
243
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
245
244
|
TAllContext extends Record<string, any> = AnyContext,
|
|
246
245
|
TRouteContext extends Record<string, any> = AnyContext,
|
|
247
246
|
TLoaderData extends any = unknown,
|
|
248
247
|
> = (
|
|
249
|
-
match: LoaderFnContext<
|
|
250
|
-
TAllParams,
|
|
251
|
-
TFullSearchSchema,
|
|
252
|
-
TAllContext,
|
|
253
|
-
TRouteContext
|
|
254
|
-
>,
|
|
248
|
+
match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
|
|
255
249
|
) => Promise<TLoaderData> | TLoaderData
|
|
256
250
|
|
|
257
251
|
export interface LoaderFnContext<
|
|
258
252
|
TAllParams = {},
|
|
259
|
-
|
|
253
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
260
254
|
TAllContext extends Record<string, any> = AnyContext,
|
|
261
255
|
TRouteContext extends Record<string, any> = AnyContext,
|
|
262
256
|
> {
|
|
263
257
|
abortController: AbortController
|
|
264
258
|
preload: boolean
|
|
265
259
|
params: TAllParams
|
|
266
|
-
|
|
260
|
+
deps: TLoaderDeps
|
|
267
261
|
context: Expand<Assign<TAllContext, TRouteContext>>
|
|
268
|
-
location: ParsedLocation
|
|
262
|
+
location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
|
|
269
263
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>
|
|
270
264
|
parentMatchPromise?: Promise<void>
|
|
271
265
|
cause: 'preload' | 'enter' | 'stay'
|
|
@@ -308,6 +302,8 @@ export interface AnyRoute
|
|
|
308
302
|
any,
|
|
309
303
|
any,
|
|
310
304
|
any,
|
|
305
|
+
any,
|
|
306
|
+
any,
|
|
311
307
|
any
|
|
312
308
|
> {}
|
|
313
309
|
|
|
@@ -425,6 +421,7 @@ export class Route<
|
|
|
425
421
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
426
422
|
>,
|
|
427
423
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
424
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
428
425
|
TLoaderData extends any = unknown,
|
|
429
426
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
430
427
|
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
@@ -440,6 +437,7 @@ export class Route<
|
|
|
440
437
|
TAllParams,
|
|
441
438
|
TRouteContext,
|
|
442
439
|
TAllContext,
|
|
440
|
+
TLoaderDeps,
|
|
443
441
|
TLoaderData
|
|
444
442
|
>
|
|
445
443
|
|
|
@@ -472,6 +470,7 @@ export class Route<
|
|
|
472
470
|
TAllParams,
|
|
473
471
|
TRouteContext,
|
|
474
472
|
TAllContext,
|
|
473
|
+
TLoaderDeps,
|
|
475
474
|
TLoaderData
|
|
476
475
|
>,
|
|
477
476
|
) {
|
|
@@ -501,6 +500,7 @@ export class Route<
|
|
|
501
500
|
routeTree: TRouteTree
|
|
502
501
|
routerContext: TRouterContext
|
|
503
502
|
loaderData: TLoaderData
|
|
503
|
+
loaderDeps: TLoaderDeps
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
init = (opts: { originalIndex: number }) => {
|
|
@@ -516,6 +516,7 @@ export class Route<
|
|
|
516
516
|
TAllParams,
|
|
517
517
|
TRouteContext,
|
|
518
518
|
TAllContext,
|
|
519
|
+
TLoaderDeps,
|
|
519
520
|
TLoaderData
|
|
520
521
|
> &
|
|
521
522
|
RoutePathOptionsIntersection<TCustomId, TPath>
|
|
@@ -585,6 +586,8 @@ export class Route<
|
|
|
585
586
|
TRouteContext,
|
|
586
587
|
TAllContext,
|
|
587
588
|
TRouterContext,
|
|
589
|
+
TLoaderDeps,
|
|
590
|
+
TLoaderData,
|
|
588
591
|
TNewChildren,
|
|
589
592
|
TRouteTree
|
|
590
593
|
> => {
|
|
@@ -632,12 +635,13 @@ export class Route<
|
|
|
632
635
|
}
|
|
633
636
|
}
|
|
634
637
|
|
|
635
|
-
export type AnyRootRoute = RootRoute<any, any, any>
|
|
638
|
+
export type AnyRootRoute = RootRoute<any, any, any, any>
|
|
636
639
|
|
|
637
640
|
export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
638
641
|
return <
|
|
639
642
|
TSearchSchema extends Record<string, any> = {},
|
|
640
643
|
TRouteContext extends RouteContext = RouteContext,
|
|
644
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
641
645
|
TLoaderData extends any = unknown,
|
|
642
646
|
>(
|
|
643
647
|
options?: Omit<
|
|
@@ -651,7 +655,8 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
|
651
655
|
{}, // TAllParams
|
|
652
656
|
TRouteContext, // TRouteContext
|
|
653
657
|
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
654
|
-
|
|
658
|
+
TLoaderDeps,
|
|
659
|
+
TLoaderData // TLoaderData,
|
|
655
660
|
>,
|
|
656
661
|
| 'path'
|
|
657
662
|
| 'id'
|
|
@@ -669,6 +674,7 @@ export class RootRoute<
|
|
|
669
674
|
TSearchSchema extends Record<string, any> = {},
|
|
670
675
|
TRouteContext extends RouteContext = RouteContext,
|
|
671
676
|
TRouterContext extends {} = {},
|
|
677
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
672
678
|
TLoaderData extends any = unknown,
|
|
673
679
|
> extends Route<
|
|
674
680
|
any, // TParentRoute
|
|
@@ -683,6 +689,7 @@ export class RootRoute<
|
|
|
683
689
|
TRouteContext, // TRouteContext
|
|
684
690
|
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
685
691
|
TRouterContext, // TRouterContext
|
|
692
|
+
TLoaderDeps,
|
|
686
693
|
TLoaderData,
|
|
687
694
|
any, // TChildren
|
|
688
695
|
any // TRouteTree
|
|
@@ -699,6 +706,7 @@ export class RootRoute<
|
|
|
699
706
|
{}, // TAllParams
|
|
700
707
|
TRouteContext, // TRouteContext
|
|
701
708
|
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
709
|
+
TLoaderDeps,
|
|
702
710
|
TLoaderData
|
|
703
711
|
>,
|
|
704
712
|
| 'path'
|
|
@@ -809,6 +817,7 @@ export class NotFoundRoute<
|
|
|
809
817
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
810
818
|
>,
|
|
811
819
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
820
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
812
821
|
TLoaderData extends any = unknown,
|
|
813
822
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
814
823
|
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
@@ -825,6 +834,7 @@ export class NotFoundRoute<
|
|
|
825
834
|
TRouteContext,
|
|
826
835
|
TAllContext,
|
|
827
836
|
TRouterContext,
|
|
837
|
+
TLoaderDeps,
|
|
828
838
|
TLoaderData,
|
|
829
839
|
TChildren,
|
|
830
840
|
TRouteTree
|
|
@@ -841,6 +851,7 @@ export class NotFoundRoute<
|
|
|
841
851
|
{},
|
|
842
852
|
TRouteContext,
|
|
843
853
|
TAllContext,
|
|
854
|
+
TLoaderDeps,
|
|
844
855
|
TLoaderData
|
|
845
856
|
>,
|
|
846
857
|
'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'
|
package/src/routeInfo.ts
CHANGED
package/src/router.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
} from './path'
|
|
60
60
|
import invariant from 'tiny-invariant'
|
|
61
61
|
import { isRedirect } from './redirects'
|
|
62
|
+
import { ToOptions } from './link'
|
|
62
63
|
// import warning from 'tiny-warning'
|
|
63
64
|
|
|
64
65
|
//
|
|
@@ -617,13 +618,21 @@ export class Router<
|
|
|
617
618
|
}
|
|
618
619
|
})()
|
|
619
620
|
|
|
621
|
+
// This is where we need to call route.options.loaderDeps() to get any additional
|
|
622
|
+
// deps that the route's loader function might need to run. We need to do this
|
|
623
|
+
// before we create the match so that we can pass the deps to the route's
|
|
624
|
+
// potential key function which is used to uniquely identify the route match in state
|
|
625
|
+
|
|
626
|
+
const loaderDeps =
|
|
627
|
+
route.options.loaderDeps?.({
|
|
628
|
+
search: preMatchSearch,
|
|
629
|
+
}) ?? ''
|
|
630
|
+
|
|
631
|
+
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : ''
|
|
632
|
+
|
|
620
633
|
const interpolatedPath = interpolatePath(route.fullPath, routeParams)
|
|
621
634
|
const matchId =
|
|
622
|
-
interpolatePath(route.id, routeParams, true) +
|
|
623
|
-
(route.options.key?.({
|
|
624
|
-
search: preMatchSearch,
|
|
625
|
-
location: this.state.location,
|
|
626
|
-
}) ?? '')
|
|
635
|
+
interpolatePath(route.id, routeParams, true) + loaderDepsHash
|
|
627
636
|
|
|
628
637
|
// Waste not, want not. If we already have a match for this route,
|
|
629
638
|
// reuse it. This is important for layout routes, which might stick
|
|
@@ -662,6 +671,7 @@ export class Router<
|
|
|
662
671
|
shouldReloadDeps: undefined,
|
|
663
672
|
fetchCount: 0,
|
|
664
673
|
cause,
|
|
674
|
+
loaderDeps,
|
|
665
675
|
}
|
|
666
676
|
|
|
667
677
|
// Regardless of whether we're reusing an existing match or creating
|
|
@@ -928,7 +938,7 @@ export class Router<
|
|
|
928
938
|
startTransition,
|
|
929
939
|
...rest
|
|
930
940
|
}: BuildNextOptions & CommitLocationOptions = {}) => {
|
|
931
|
-
const location = this.buildLocation(rest)
|
|
941
|
+
const location = this.buildLocation(rest as any)
|
|
932
942
|
return this.commitLocation({
|
|
933
943
|
...location,
|
|
934
944
|
startTransition,
|
|
@@ -1133,7 +1143,7 @@ export class Router<
|
|
|
1133
1143
|
} else {
|
|
1134
1144
|
const loaderContext: LoaderFnContext = {
|
|
1135
1145
|
params: match.params,
|
|
1136
|
-
|
|
1146
|
+
deps: match.loaderDeps,
|
|
1137
1147
|
preload: !!preload,
|
|
1138
1148
|
parentMatchPromise,
|
|
1139
1149
|
abortController: match.abortController,
|
|
@@ -1452,9 +1462,9 @@ export class Router<
|
|
|
1452
1462
|
}
|
|
1453
1463
|
|
|
1454
1464
|
preloadRoute = async (
|
|
1455
|
-
navigateOpts:
|
|
1465
|
+
navigateOpts: ToOptions<TRouteTree> = this.state.location as any,
|
|
1456
1466
|
) => {
|
|
1457
|
-
let next = this.buildLocation(navigateOpts)
|
|
1467
|
+
let next = this.buildLocation(navigateOpts as any)
|
|
1458
1468
|
|
|
1459
1469
|
let matches = this.matchRoutes(next.pathname, next.search, {
|
|
1460
1470
|
throwOnError: true,
|