@tanstack/react-router 0.0.1-beta.208 → 0.0.1-beta.209
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/RouterProvider.js +14 -14
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/index.js +2 -2
- package/build/cjs/react.js +7 -7
- package/build/cjs/react.js.map +1 -1
- package/build/cjs/route.js +6 -13
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +27 -34
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +170 -170
- package/build/types/RouteMatch.d.ts +1 -1
- package/build/types/fileRoute.d.ts +17 -2
- package/build/types/react.d.ts +4 -4
- package/build/types/route.d.ts +42 -38
- package/build/types/router.d.ts +5 -5
- package/build/umd/index.development.js +28 -35
- 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/RouteMatch.ts +1 -1
- package/src/RouterProvider.tsx +15 -15
- package/src/fileRoute.ts +10 -8
- package/src/react.tsx +13 -11
- package/src/route.ts +108 -105
- package/src/router.ts +6 -6
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.209",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
|
-
"@tanstack/history": "0.0.1-beta.
|
|
45
|
+
"@tanstack/history": "0.0.1-beta.209"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup --config rollup.config.js"
|
package/src/RouteMatch.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface RouteMatch<
|
|
|
18
18
|
updatedAt: number
|
|
19
19
|
loadPromise?: Promise<void>
|
|
20
20
|
__resolveLoadPromise?: () => void
|
|
21
|
-
|
|
21
|
+
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
22
22
|
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
|
|
23
23
|
search: FullSearchSchema<TRouteTree> &
|
|
24
24
|
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -159,13 +159,13 @@ export function RouterProvider<
|
|
|
159
159
|
const options = {
|
|
160
160
|
...router.options,
|
|
161
161
|
...rest,
|
|
162
|
-
|
|
163
|
-
...router.options.
|
|
164
|
-
...rest?.
|
|
162
|
+
context: {
|
|
163
|
+
...router.options.context,
|
|
164
|
+
...rest?.context,
|
|
165
165
|
},
|
|
166
166
|
} as PickAsRequired<
|
|
167
167
|
RouterOptions<TRouteTree, TDehydrated>,
|
|
168
|
-
'stringifySearch' | 'parseSearch' | '
|
|
168
|
+
'stringifySearch' | 'parseSearch' | 'context'
|
|
169
169
|
>
|
|
170
170
|
|
|
171
171
|
const history = React.useState(
|
|
@@ -451,7 +451,7 @@ export function RouterProvider<
|
|
|
451
451
|
paramsError: parseErrors[index],
|
|
452
452
|
searchError: undefined,
|
|
453
453
|
loadPromise: Promise.resolve(),
|
|
454
|
-
|
|
454
|
+
context: undefined!,
|
|
455
455
|
abortController: new AbortController(),
|
|
456
456
|
fetchedAt: 0,
|
|
457
457
|
}
|
|
@@ -459,9 +459,9 @@ export function RouterProvider<
|
|
|
459
459
|
return routeMatch
|
|
460
460
|
})
|
|
461
461
|
|
|
462
|
-
// Take each match and resolve its search params and
|
|
462
|
+
// Take each match and resolve its search params and context
|
|
463
463
|
// This has to happen after the matches are created or found
|
|
464
|
-
// so that we can use the parent match's search params and
|
|
464
|
+
// so that we can use the parent match's search params and context
|
|
465
465
|
matches.forEach((match, i): any => {
|
|
466
466
|
const parentMatch = matches[i - 1]
|
|
467
467
|
const route = looseRoutesById[match.routeId]!
|
|
@@ -848,27 +848,27 @@ export function RouterProvider<
|
|
|
848
848
|
handleError(match.searchError, 'VALIDATE_SEARCH')
|
|
849
849
|
}
|
|
850
850
|
|
|
851
|
-
const
|
|
851
|
+
const parentContext = parentMatch?.context ?? options.context ?? {}
|
|
852
852
|
|
|
853
|
-
const
|
|
853
|
+
const beforeLoadContext =
|
|
854
854
|
(await route.options.beforeLoad?.({
|
|
855
855
|
search: match.search,
|
|
856
856
|
abortController: match.abortController,
|
|
857
857
|
params: match.params,
|
|
858
858
|
preload: !!preload,
|
|
859
|
-
|
|
859
|
+
context: parentContext,
|
|
860
860
|
location: state.location, // TODO: This might need to be latestLocationRef.current...?
|
|
861
861
|
navigate: (opts) => navigate({ ...opts, from: match.pathname }),
|
|
862
862
|
})) ?? ({} as any)
|
|
863
863
|
|
|
864
|
-
const
|
|
865
|
-
...
|
|
866
|
-
...
|
|
864
|
+
const context = {
|
|
865
|
+
...parentContext,
|
|
866
|
+
...beforeLoadContext,
|
|
867
867
|
}
|
|
868
868
|
|
|
869
869
|
matches[index] = match = {
|
|
870
870
|
...match,
|
|
871
|
-
|
|
871
|
+
context: replaceEqualDeep(match.context, context),
|
|
872
872
|
}
|
|
873
873
|
} catch (err) {
|
|
874
874
|
handleError(err, 'BEFORE_LOAD')
|
|
@@ -925,7 +925,7 @@ export function RouterProvider<
|
|
|
925
925
|
preload: !!preload,
|
|
926
926
|
parentMatchPromise,
|
|
927
927
|
abortController: match.abortController,
|
|
928
|
-
|
|
928
|
+
context: match.context,
|
|
929
929
|
location: state.location,
|
|
930
930
|
navigate: (opts) =>
|
|
931
931
|
navigate({ ...opts, from: match.pathname }),
|
package/src/fileRoute.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ResolveFullPath,
|
|
5
5
|
ResolveFullSearchSchema,
|
|
6
6
|
MergeFromFromParent,
|
|
7
|
-
|
|
7
|
+
RouteContext,
|
|
8
8
|
AnyContext,
|
|
9
9
|
RouteOptions,
|
|
10
10
|
UpdatableRouteOptions,
|
|
@@ -97,11 +97,13 @@ export class FileRoute<
|
|
|
97
97
|
TParentRoute['types']['allParams'],
|
|
98
98
|
TParams
|
|
99
99
|
>,
|
|
100
|
-
|
|
100
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
101
101
|
TContext extends Expand<
|
|
102
|
-
Assign<IsAny<TParentRoute['types']['
|
|
103
|
-
> = Expand<
|
|
104
|
-
|
|
102
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
103
|
+
> = Expand<
|
|
104
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
105
|
+
>,
|
|
106
|
+
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
105
107
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
106
108
|
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
107
109
|
>(
|
|
@@ -114,7 +116,7 @@ export class FileRoute<
|
|
|
114
116
|
TFullSearchSchema,
|
|
115
117
|
TParams,
|
|
116
118
|
TAllParams,
|
|
117
|
-
|
|
119
|
+
TRouteContext,
|
|
118
120
|
TContext
|
|
119
121
|
>,
|
|
120
122
|
'getParentRoute' | 'path' | 'id'
|
|
@@ -130,9 +132,9 @@ export class FileRoute<
|
|
|
130
132
|
TFullSearchSchema,
|
|
131
133
|
TParams,
|
|
132
134
|
TAllParams,
|
|
133
|
-
|
|
135
|
+
TRouteContext,
|
|
134
136
|
TContext,
|
|
135
|
-
|
|
137
|
+
TRouterContext,
|
|
136
138
|
TChildren,
|
|
137
139
|
TRouteTree
|
|
138
140
|
> => {
|
package/src/react.tsx
CHANGED
|
@@ -40,7 +40,7 @@ export type RouteProps<
|
|
|
40
40
|
useMatch: <TSelected = TAllContext>(opts?: {
|
|
41
41
|
select?: (search: TAllContext) => TSelected
|
|
42
42
|
}) => TSelected
|
|
43
|
-
|
|
43
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
44
44
|
select?: (search: TAllContext) => TSelected
|
|
45
45
|
}) => TSelected
|
|
46
46
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
@@ -398,7 +398,7 @@ export type RouterProps<
|
|
|
398
398
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
399
399
|
> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
400
400
|
router: Router<TRouteTree>
|
|
401
|
-
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['
|
|
401
|
+
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
export function useRouter<
|
|
@@ -515,21 +515,23 @@ export type RouteFromIdOrRoute<
|
|
|
515
515
|
? RouteIds<TRouteTree>
|
|
516
516
|
: never
|
|
517
517
|
|
|
518
|
-
export function
|
|
518
|
+
export function useRouteContext<
|
|
519
519
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
520
520
|
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
521
521
|
TStrict extends boolean = true,
|
|
522
|
-
|
|
523
|
-
TSelected =
|
|
522
|
+
TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],
|
|
523
|
+
TSelected = TRouteContext,
|
|
524
524
|
>(
|
|
525
525
|
opts: StrictOrFrom<TFrom> & {
|
|
526
|
-
select?: (search:
|
|
526
|
+
select?: (search: TRouteContext) => TSelected
|
|
527
527
|
},
|
|
528
528
|
): TStrict extends true ? TSelected : TSelected | undefined {
|
|
529
529
|
return useMatch({
|
|
530
530
|
...(opts as any),
|
|
531
531
|
select: (match: RouteMatch) =>
|
|
532
|
-
opts?.select
|
|
532
|
+
opts?.select
|
|
533
|
+
? opts.select(match.context as TRouteContext)
|
|
534
|
+
: match.context,
|
|
533
535
|
})
|
|
534
536
|
}
|
|
535
537
|
|
|
@@ -666,7 +668,7 @@ export function Matches() {
|
|
|
666
668
|
return React.createElement(ErrorComponent, {
|
|
667
669
|
...props,
|
|
668
670
|
useMatch: route.useMatch,
|
|
669
|
-
|
|
671
|
+
useRouteContext: route.useRouteContext,
|
|
670
672
|
useSearch: route.useSearch,
|
|
671
673
|
useParams: route.useParams,
|
|
672
674
|
})
|
|
@@ -755,7 +757,7 @@ function Match({ matches }: { matches: RouteMatch[] }) {
|
|
|
755
757
|
return React.createElement(routeErrorComponent, {
|
|
756
758
|
...props,
|
|
757
759
|
useMatch: route.useMatch,
|
|
758
|
-
|
|
760
|
+
useRouteContext: route.useRouteContext,
|
|
759
761
|
useSearch: route.useSearch,
|
|
760
762
|
useParams: route.useParams,
|
|
761
763
|
})
|
|
@@ -768,7 +770,7 @@ function Match({ matches }: { matches: RouteMatch[] }) {
|
|
|
768
770
|
<ResolvedSuspenseBoundary
|
|
769
771
|
fallback={React.createElement(PendingComponent, {
|
|
770
772
|
useMatch: route.useMatch,
|
|
771
|
-
|
|
773
|
+
useRouteContext: route.useRouteContext,
|
|
772
774
|
useSearch: route.useSearch,
|
|
773
775
|
useParams: route.useParams,
|
|
774
776
|
})}
|
|
@@ -805,7 +807,7 @@ function MatchInner({ match }: { match: RouteMatch }): any {
|
|
|
805
807
|
if (comp) {
|
|
806
808
|
return React.createElement(comp, {
|
|
807
809
|
useMatch: route.useMatch,
|
|
808
|
-
|
|
810
|
+
useRouteContext: route.useRouteContext as any,
|
|
809
811
|
useSearch: route.useSearch,
|
|
810
812
|
useParams: route.useParams as any,
|
|
811
813
|
} as any)
|
package/src/route.ts
CHANGED
|
@@ -29,6 +29,7 @@ export type RootRouteId = typeof rootRouteId
|
|
|
29
29
|
export type AnyPathParams = {}
|
|
30
30
|
export type AnySearchSchema = {}
|
|
31
31
|
export type AnyContext = {}
|
|
32
|
+
export interface RouteContext {}
|
|
32
33
|
export interface RouteMeta {}
|
|
33
34
|
|
|
34
35
|
export type PreloadableObj = { preload?: () => Promise<void> }
|
|
@@ -44,13 +45,13 @@ export type RoutePathOptions<TCustomId, TPath> =
|
|
|
44
45
|
export type RoutePathOptionsIntersection<TCustomId, TPath> =
|
|
45
46
|
UnionToIntersection<RoutePathOptions<TCustomId, TPath>>
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
export type MetaOptions = keyof PickRequired<RouteMeta> extends never
|
|
49
|
+
? {
|
|
50
|
+
meta?: RouteMeta
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
meta: RouteMeta
|
|
54
|
+
}
|
|
54
55
|
|
|
55
56
|
export type RouteOptions<
|
|
56
57
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
@@ -60,8 +61,8 @@ export type RouteOptions<
|
|
|
60
61
|
TFullSearchSchema extends Record<string, any> = TSearchSchema,
|
|
61
62
|
TParams extends AnyPathParams = AnyPathParams,
|
|
62
63
|
TAllParams extends AnyPathParams = TParams,
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
TRouteContext extends RouteContext = RouteContext,
|
|
65
|
+
TAllContext extends Record<string, any> = AnyContext,
|
|
65
66
|
> = BaseRouteOptions<
|
|
66
67
|
TParentRoute,
|
|
67
68
|
TCustomId,
|
|
@@ -70,10 +71,10 @@ export type RouteOptions<
|
|
|
70
71
|
TFullSearchSchema,
|
|
71
72
|
TParams,
|
|
72
73
|
TAllParams,
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
TRouteContext,
|
|
75
|
+
TAllContext
|
|
75
76
|
> &
|
|
76
|
-
NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams,
|
|
77
|
+
NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams, TAllContext>>
|
|
77
78
|
|
|
78
79
|
export type ParamsFallback<
|
|
79
80
|
TPath extends string,
|
|
@@ -92,12 +93,12 @@ export type BaseRouteOptions<
|
|
|
92
93
|
TFullSearchSchema extends Record<string, any> = TSearchSchema,
|
|
93
94
|
TParams extends AnyPathParams = {},
|
|
94
95
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
95
|
-
|
|
96
|
+
TRouteContext extends RouteContext = RouteContext,
|
|
96
97
|
TAllContext extends Record<string, any> = AnyContext,
|
|
97
98
|
> = RoutePathOptions<TCustomId, TPath> & {
|
|
98
99
|
getParentRoute: () => TParentRoute
|
|
99
100
|
validateSearch?: SearchSchemaValidator<TSearchSchema>
|
|
100
|
-
} & (keyof PickRequired<
|
|
101
|
+
} & (keyof PickRequired<RouteContext> extends never
|
|
101
102
|
? // This async function is called before a route is loaded.
|
|
102
103
|
// If an error is thrown here, the route's loader will not be called.
|
|
103
104
|
// If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.
|
|
@@ -107,7 +108,7 @@ export type BaseRouteOptions<
|
|
|
107
108
|
TFullSearchSchema,
|
|
108
109
|
TParentRoute,
|
|
109
110
|
TAllParams,
|
|
110
|
-
|
|
111
|
+
TRouteContext
|
|
111
112
|
>
|
|
112
113
|
}
|
|
113
114
|
: {
|
|
@@ -115,14 +116,14 @@ export type BaseRouteOptions<
|
|
|
115
116
|
TFullSearchSchema,
|
|
116
117
|
TParentRoute,
|
|
117
118
|
TAllParams,
|
|
118
|
-
|
|
119
|
+
TRouteContext
|
|
119
120
|
>
|
|
120
121
|
}) & {
|
|
121
122
|
load?: RouteLoadFn<
|
|
122
123
|
TAllParams,
|
|
123
124
|
TFullSearchSchema,
|
|
124
125
|
NoInfer<TAllContext>,
|
|
125
|
-
NoInfer<
|
|
126
|
+
NoInfer<TRouteContext>
|
|
126
127
|
>
|
|
127
128
|
} & (
|
|
128
129
|
| {
|
|
@@ -146,61 +147,59 @@ type BeforeLoadFn<
|
|
|
146
147
|
TFullSearchSchema extends Record<string, any>,
|
|
147
148
|
TParentRoute extends AnyRoute,
|
|
148
149
|
TAllParams,
|
|
149
|
-
|
|
150
|
+
TRouteContext,
|
|
150
151
|
> = (opts: {
|
|
151
152
|
search: TFullSearchSchema
|
|
152
153
|
abortController: AbortController
|
|
153
154
|
preload: boolean
|
|
154
155
|
params: TAllParams
|
|
155
|
-
|
|
156
|
+
context: TParentRoute['types']['allContext']
|
|
156
157
|
location: ParsedLocation
|
|
157
158
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>
|
|
158
|
-
}) => Promise<
|
|
159
|
+
}) => Promise<TRouteContext> | TRouteContext | void
|
|
159
160
|
|
|
160
161
|
export type UpdatableRouteOptions<
|
|
161
162
|
TFullSearchSchema extends Record<string, any>,
|
|
162
163
|
TAllParams extends AnyPathParams,
|
|
163
164
|
TAllContext extends AnyContext,
|
|
164
|
-
> =
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
reloadOnWindowFocus?: boolean
|
|
203
|
-
}
|
|
165
|
+
> = MetaOptions & {
|
|
166
|
+
// test?: (args: TAllContext) => void
|
|
167
|
+
// If true, this route will be matched as case-sensitive
|
|
168
|
+
caseSensitive?: boolean
|
|
169
|
+
// If true, this route will be forcefully wrapped in a suspense boundary
|
|
170
|
+
wrapInSuspense?: boolean
|
|
171
|
+
// The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
|
|
172
|
+
component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext>
|
|
173
|
+
// The content to be rendered when the route encounters an error
|
|
174
|
+
errorComponent?: ErrorRouteComponent<
|
|
175
|
+
TFullSearchSchema,
|
|
176
|
+
TAllParams,
|
|
177
|
+
{}
|
|
178
|
+
// TAllContext // TODO: I have no idea why this breaks the universe,
|
|
179
|
+
// so we'll come back to it later.
|
|
180
|
+
> //
|
|
181
|
+
// If supported by your framework, the content to be rendered as the fallback content until the route is ready to render
|
|
182
|
+
pendingComponent?: PendingRouteComponent<
|
|
183
|
+
TFullSearchSchema,
|
|
184
|
+
TAllParams,
|
|
185
|
+
TAllContext
|
|
186
|
+
>
|
|
187
|
+
// Filter functions that can manipulate search params *before* they are passed to links and navigate
|
|
188
|
+
// calls that match this route.
|
|
189
|
+
preSearchFilters?: SearchFilter<TFullSearchSchema>[]
|
|
190
|
+
// Filter functions that can manipulate search params *after* they are passed to links and navigate
|
|
191
|
+
// calls that match this route.
|
|
192
|
+
postSearchFilters?: SearchFilter<TFullSearchSchema>[]
|
|
193
|
+
onError?: (err: any) => void
|
|
194
|
+
// These functions are called as route matches are loaded, stick around and leave the active
|
|
195
|
+
// matches
|
|
196
|
+
onEnter?: (match: AnyRouteMatch) => void
|
|
197
|
+
onTransition?: (match: AnyRouteMatch) => void
|
|
198
|
+
onLeave?: (match: AnyRouteMatch) => void
|
|
199
|
+
// Set this to true or false to specifically set whether or not this route should be preloaded. If unset, will
|
|
200
|
+
// default to router.options.reloadOnWindowFocus
|
|
201
|
+
reloadOnWindowFocus?: boolean
|
|
202
|
+
}
|
|
204
203
|
|
|
205
204
|
export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<
|
|
206
205
|
TPath,
|
|
@@ -243,13 +242,13 @@ export type RouteLoadFn<
|
|
|
243
242
|
TAllParams = {},
|
|
244
243
|
TFullSearchSchema extends Record<string, any> = {},
|
|
245
244
|
TAllContext extends Record<string, any> = AnyContext,
|
|
246
|
-
|
|
245
|
+
TRouteContext extends Record<string, any> = AnyContext,
|
|
247
246
|
> = (
|
|
248
247
|
match: LoadFnContext<
|
|
249
248
|
TAllParams,
|
|
250
249
|
TFullSearchSchema,
|
|
251
250
|
TAllContext,
|
|
252
|
-
|
|
251
|
+
TRouteContext
|
|
253
252
|
> & {
|
|
254
253
|
parentMatchPromise?: Promise<void>
|
|
255
254
|
},
|
|
@@ -259,13 +258,13 @@ export interface LoadFnContext<
|
|
|
259
258
|
TAllParams = {},
|
|
260
259
|
TFullSearchSchema extends Record<string, any> = {},
|
|
261
260
|
TAllContext extends Record<string, any> = AnyContext,
|
|
262
|
-
|
|
261
|
+
TRouteContext extends Record<string, any> = AnyContext,
|
|
263
262
|
> {
|
|
264
263
|
abortController: AbortController
|
|
265
264
|
preload: boolean
|
|
266
265
|
params: TAllParams
|
|
267
266
|
search: TFullSearchSchema
|
|
268
|
-
|
|
267
|
+
context: Expand<Assign<TAllContext, TRouteContext>>
|
|
269
268
|
location: ParsedLocation<TFullSearchSchema>
|
|
270
269
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>
|
|
271
270
|
}
|
|
@@ -339,9 +338,9 @@ export type RouteConstraints = {
|
|
|
339
338
|
TParams: Record<string, any>
|
|
340
339
|
TAllParams: Record<string, any>
|
|
341
340
|
TParentContext: AnyContext
|
|
342
|
-
|
|
341
|
+
TRouteContext: RouteContext
|
|
343
342
|
TAllContext: AnyContext
|
|
344
|
-
|
|
343
|
+
TRouterContext: AnyContext
|
|
345
344
|
TChildren: unknown
|
|
346
345
|
TRouteTree: AnyRoute
|
|
347
346
|
}
|
|
@@ -371,11 +370,13 @@ export class Route<
|
|
|
371
370
|
TParentRoute,
|
|
372
371
|
TParams
|
|
373
372
|
>,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
Assign<IsAny<TParentRoute['types']['
|
|
377
|
-
> = Expand<
|
|
378
|
-
|
|
373
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
374
|
+
TAllContext extends Expand<
|
|
375
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
376
|
+
> = Expand<
|
|
377
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
378
|
+
>,
|
|
379
|
+
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
379
380
|
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
380
381
|
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
381
382
|
> {
|
|
@@ -388,11 +389,13 @@ export class Route<
|
|
|
388
389
|
TFullSearchSchema,
|
|
389
390
|
TParams,
|
|
390
391
|
TAllParams,
|
|
391
|
-
|
|
392
|
-
|
|
392
|
+
TRouteContext,
|
|
393
|
+
TAllContext
|
|
393
394
|
>
|
|
394
395
|
|
|
395
|
-
test!: Expand<
|
|
396
|
+
test!: Expand<
|
|
397
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
398
|
+
>
|
|
396
399
|
|
|
397
400
|
// Set up in this.init()
|
|
398
401
|
parentRoute!: TParentRoute
|
|
@@ -417,8 +420,8 @@ export class Route<
|
|
|
417
420
|
TFullSearchSchema,
|
|
418
421
|
TParams,
|
|
419
422
|
TAllParams,
|
|
420
|
-
|
|
421
|
-
|
|
423
|
+
TRouteContext,
|
|
424
|
+
TAllContext
|
|
422
425
|
>,
|
|
423
426
|
) {
|
|
424
427
|
this.options = (options as any) || {}
|
|
@@ -437,11 +440,11 @@ export class Route<
|
|
|
437
440
|
fullSearchSchema: TFullSearchSchema
|
|
438
441
|
params: TParams
|
|
439
442
|
allParams: TAllParams
|
|
440
|
-
|
|
441
|
-
|
|
443
|
+
routeContext: TRouteContext
|
|
444
|
+
allContext: TAllContext
|
|
442
445
|
children: TChildren
|
|
443
446
|
routeTree: TRouteTree
|
|
444
|
-
|
|
447
|
+
routerContext: TRouterContext
|
|
445
448
|
}
|
|
446
449
|
|
|
447
450
|
init = (opts: { originalIndex: number }) => {
|
|
@@ -455,8 +458,8 @@ export class Route<
|
|
|
455
458
|
TFullSearchSchema,
|
|
456
459
|
TParams,
|
|
457
460
|
TAllParams,
|
|
458
|
-
|
|
459
|
-
|
|
461
|
+
TRouteContext,
|
|
462
|
+
TAllContext
|
|
460
463
|
> &
|
|
461
464
|
RoutePathOptionsIntersection<TCustomId, TPath>
|
|
462
465
|
|
|
@@ -522,9 +525,9 @@ export class Route<
|
|
|
522
525
|
TFullSearchSchema,
|
|
523
526
|
TParams,
|
|
524
527
|
TAllParams,
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
+
TRouteContext,
|
|
529
|
+
TAllContext,
|
|
530
|
+
TRouterContext,
|
|
528
531
|
TNewChildren,
|
|
529
532
|
TRouteTree
|
|
530
533
|
> => {
|
|
@@ -536,7 +539,9 @@ export class Route<
|
|
|
536
539
|
options: UpdatableRouteOptions<
|
|
537
540
|
TFullSearchSchema,
|
|
538
541
|
TAllParams,
|
|
539
|
-
Expand<
|
|
542
|
+
Expand<
|
|
543
|
+
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
544
|
+
>
|
|
540
545
|
>,
|
|
541
546
|
) => {
|
|
542
547
|
Object.assign(this.options, options)
|
|
@@ -548,18 +553,18 @@ export class Route<
|
|
|
548
553
|
// replaced by a framework specific implementation if necessary
|
|
549
554
|
}
|
|
550
555
|
|
|
551
|
-
useMatch = <TSelected =
|
|
552
|
-
select?: (search:
|
|
556
|
+
useMatch = <TSelected = TAllContext>(opts?: {
|
|
557
|
+
select?: (search: TAllContext) => TSelected
|
|
553
558
|
}): TSelected => {
|
|
554
559
|
return useMatch({ ...opts, from: this.id }) as any
|
|
555
560
|
}
|
|
556
|
-
|
|
557
|
-
select?: (search:
|
|
561
|
+
useRouteContext = <TSelected = TAllContext>(opts?: {
|
|
562
|
+
select?: (search: TAllContext) => TSelected
|
|
558
563
|
}): TSelected => {
|
|
559
564
|
return useMatch({
|
|
560
565
|
...opts,
|
|
561
566
|
from: this.id,
|
|
562
|
-
select: (d: any) => (opts?.select ? opts.select(d.
|
|
567
|
+
select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
|
|
563
568
|
} as any)
|
|
564
569
|
}
|
|
565
570
|
useSearch = <TSelected = TFullSearchSchema>(opts?: {
|
|
@@ -576,12 +581,10 @@ export class Route<
|
|
|
576
581
|
|
|
577
582
|
export type AnyRootRoute = RootRoute<any, any, any>
|
|
578
583
|
|
|
579
|
-
export
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
createRootRoute = <
|
|
584
|
+
export function rootRouteWithContext<TRouterContext extends {}>() {
|
|
585
|
+
return <
|
|
583
586
|
TSearchSchema extends Record<string, any> = {},
|
|
584
|
-
|
|
587
|
+
TRouteContext extends RouteContext = RouteContext,
|
|
585
588
|
>(
|
|
586
589
|
options?: Omit<
|
|
587
590
|
RouteOptions<
|
|
@@ -592,8 +595,8 @@ export class RouterMeta<TRouterMeta extends {}> {
|
|
|
592
595
|
TSearchSchema, // TFullSearchSchema
|
|
593
596
|
{}, // TParams
|
|
594
597
|
{}, // TAllParams
|
|
595
|
-
|
|
596
|
-
Assign<
|
|
598
|
+
TRouteContext, // TRouteContext
|
|
599
|
+
Assign<TRouterContext, TRouteContext> // TAllContext
|
|
597
600
|
>,
|
|
598
601
|
| 'path'
|
|
599
602
|
| 'id'
|
|
@@ -602,15 +605,15 @@ export class RouterMeta<TRouterMeta extends {}> {
|
|
|
602
605
|
| 'parseParams'
|
|
603
606
|
| 'stringifyParams'
|
|
604
607
|
>,
|
|
605
|
-
): RootRoute<TSearchSchema,
|
|
608
|
+
): RootRoute<TSearchSchema, TRouteContext, TRouterContext> => {
|
|
606
609
|
return new RootRoute(options) as any
|
|
607
610
|
}
|
|
608
611
|
}
|
|
609
612
|
|
|
610
613
|
export class RootRoute<
|
|
611
614
|
TSearchSchema extends Record<string, any> = {},
|
|
612
|
-
|
|
613
|
-
|
|
615
|
+
TRouteContext extends RouteContext = RouteContext,
|
|
616
|
+
TRouterContext extends {} = {},
|
|
614
617
|
> extends Route<
|
|
615
618
|
any, // TParentRoute
|
|
616
619
|
'/', // TPath
|
|
@@ -621,9 +624,9 @@ export class RootRoute<
|
|
|
621
624
|
TSearchSchema, // TFullSearchSchema
|
|
622
625
|
{}, // TParams
|
|
623
626
|
{}, // TAllParams
|
|
624
|
-
|
|
625
|
-
Expand<Assign<
|
|
626
|
-
|
|
627
|
+
TRouteContext, // TRouteContext
|
|
628
|
+
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
629
|
+
TRouterContext, // TRouterContext
|
|
627
630
|
any, // TChildren
|
|
628
631
|
any // TRouteTree
|
|
629
632
|
> {
|
|
@@ -637,8 +640,8 @@ export class RootRoute<
|
|
|
637
640
|
TSearchSchema, // TFullSearchSchema
|
|
638
641
|
{}, // TParams
|
|
639
642
|
{}, // TAllParams
|
|
640
|
-
|
|
641
|
-
Assign<
|
|
643
|
+
TRouteContext, // TRouteContext
|
|
644
|
+
Assign<TRouterContext, TRouteContext> // TAllContext
|
|
642
645
|
>,
|
|
643
646
|
| 'path'
|
|
644
647
|
| 'id'
|