@tanstack/router-core 0.0.1-beta.191 → 0.0.1-beta.193
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/fileRoute.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +29 -18
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +29 -18
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +124 -124
- package/build/types/fileRoute.d.ts +3 -4
- package/build/types/link.d.ts +9 -9
- package/build/types/route.d.ts +43 -59
- package/build/types/routeInfo.d.ts +4 -4
- package/build/types/router.d.ts +1 -2
- package/build/types/utils.d.ts +7 -0
- package/build/umd/index.development.js +29 -18
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +4 -2
- package/src/link.ts +27 -14
- package/src/route.ts +118 -135
- package/src/routeInfo.ts +11 -6
- package/src/router.ts +50 -24
- package/src/utils.ts +20 -0
package/build/types/link.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Trim } from './fileRoute';
|
|
2
2
|
import { AnyRoute } from './route';
|
|
3
|
-
import { AllParams, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
4
|
-
import { LocationState, ParsedLocation } from './router';
|
|
3
|
+
import { AllParams, FullSearchSchema, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
4
|
+
import { LocationState, ParsedLocation, RegisteredRouter } from './router';
|
|
5
5
|
import { Expand, NoInfer, NonNullableUpdater, PickRequired, UnionToIntersection, Updater } from './utils';
|
|
6
6
|
export type LinkInfo = {
|
|
7
7
|
type: 'external';
|
|
@@ -37,23 +37,23 @@ export type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends st
|
|
|
37
37
|
] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
|
|
38
38
|
length: 0;
|
|
39
39
|
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
40
|
-
export type NavigateOptions<TRouteTree extends AnyRoute =
|
|
40
|
+
export type NavigateOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
41
41
|
replace?: boolean;
|
|
42
42
|
resetScroll?: boolean;
|
|
43
43
|
};
|
|
44
|
-
export type ToOptions<TRouteTree extends AnyRoute =
|
|
44
|
+
export type ToOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TFrom, TTo> & {
|
|
45
45
|
mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>;
|
|
46
46
|
};
|
|
47
|
-
export type ToMaskOptions<TRouteTree extends AnyRoute =
|
|
47
|
+
export type ToMaskOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
48
48
|
unmaskOnReload?: boolean;
|
|
49
49
|
};
|
|
50
|
-
export type ToSubOptions<TRouteTree extends AnyRoute =
|
|
50
|
+
export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
51
51
|
to?: ToPathOption<TRouteTree, TFrom, TTo>;
|
|
52
52
|
hash?: true | Updater<string>;
|
|
53
53
|
state?: true | NonNullableUpdater<LocationState>;
|
|
54
54
|
from?: TFrom;
|
|
55
|
-
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
|
|
56
|
-
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TFromSearchEnsured = Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = Expand<RouteByPath<TRouteTree,
|
|
55
|
+
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
|
|
56
|
+
export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>, TFromSearchEnsured = '/' extends TFrom ? FullSearchSchema<TRouteTree> : Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>>, TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = '' extends TTo ? FullSearchSchema<TRouteTree> : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>> = keyof PickRequired<TToSearch> extends never ? {
|
|
57
57
|
search?: true | SearchReducer<TFromSearch, TToSearch>;
|
|
58
58
|
} : {
|
|
59
59
|
search: TFromSearchEnsured extends PickRequired<TToSearch> ? true | SearchReducer<TFromSearch, TToSearch> : SearchReducer<TFromSearch, TToSearch>;
|
|
@@ -72,7 +72,7 @@ export interface ActiveOptions {
|
|
|
72
72
|
includeHash?: boolean;
|
|
73
73
|
includeSearch?: boolean;
|
|
74
74
|
}
|
|
75
|
-
export type LinkOptions<TRouteTree extends AnyRoute =
|
|
75
|
+
export type LinkOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
76
76
|
target?: HTMLAnchorElement['target'];
|
|
77
77
|
activeOptions?: ActiveOptions;
|
|
78
78
|
preload?: false | 'intent';
|
package/build/types/route.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RoutePaths } from './routeInfo';
|
|
2
|
-
import { AnyRouter,
|
|
3
|
-
import { Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
2
|
+
import { AnyRouter, AnyRouteMatch } from './router';
|
|
3
|
+
import { DeepMerge, DeepMergeAll, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
4
4
|
import { ParsePathParams, ToSubOptions } from './link';
|
|
5
5
|
export declare const rootRouteId: "__root__";
|
|
6
6
|
export type RootRouteId = typeof rootRouteId;
|
|
@@ -11,34 +11,34 @@ export interface RouteMeta {
|
|
|
11
11
|
}
|
|
12
12
|
export interface RouteContext {
|
|
13
13
|
}
|
|
14
|
-
export interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends
|
|
14
|
+
export interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
15
15
|
}
|
|
16
|
-
export interface RegisterErrorRouteComponent<TFullSearchSchema extends
|
|
16
|
+
export interface RegisterErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
17
17
|
}
|
|
18
|
-
export interface RegisterPendingRouteComponent<TFullSearchSchema extends
|
|
18
|
+
export interface RegisterPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
19
19
|
}
|
|
20
|
-
export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends
|
|
20
|
+
export interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
21
21
|
}
|
|
22
|
-
export interface RegisterErrorRouteProps<TFullSearchSchema extends
|
|
22
|
+
export interface RegisterErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
23
23
|
}
|
|
24
|
-
export interface RegisterPendingRouteProps<TFullSearchSchema extends
|
|
24
|
+
export interface RegisterPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> {
|
|
25
25
|
}
|
|
26
|
-
export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends
|
|
26
|
+
export type RegisteredRouteComponent<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
27
27
|
RouteComponent: infer T;
|
|
28
28
|
} ? T : () => unknown;
|
|
29
|
-
export type RegisteredErrorRouteComponent<TFullSearchSchema extends
|
|
29
|
+
export type RegisteredErrorRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterErrorRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
30
30
|
ErrorRouteComponent: infer T;
|
|
31
31
|
} ? T : () => unknown;
|
|
32
|
-
export type RegisteredPendingRouteComponent<TFullSearchSchema extends
|
|
32
|
+
export type RegisteredPendingRouteComponent<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterPendingRouteComponent<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
33
33
|
PendingRouteComponent: infer T;
|
|
34
34
|
} ? T : () => unknown;
|
|
35
|
-
export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends
|
|
35
|
+
export type RegisteredRouteProps<TLoader = unknown, TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
36
36
|
RouteProps: infer T;
|
|
37
37
|
} ? T : {};
|
|
38
|
-
export type RegisteredErrorRouteProps<TFullSearchSchema extends
|
|
38
|
+
export type RegisteredErrorRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
39
39
|
ErrorRouteProps: infer T;
|
|
40
40
|
} ? T : {};
|
|
41
|
-
export type RegisteredPendingRouteProps<TFullSearchSchema extends
|
|
41
|
+
export type RegisteredPendingRouteProps<TFullSearchSchema extends Record<string, any> = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext> = RegisterRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext> extends {
|
|
42
42
|
PendingRouteProps: infer T;
|
|
43
43
|
} ? T : {};
|
|
44
44
|
export type PreloadableObj = {
|
|
@@ -56,17 +56,21 @@ export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
|
56
56
|
meta: RouteMeta;
|
|
57
57
|
};
|
|
58
58
|
export type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
|
|
59
|
-
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string,
|
|
59
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
60
60
|
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
61
|
-
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string,
|
|
61
|
+
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
|
|
62
62
|
getParentRoute: () => TParentRoute;
|
|
63
63
|
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
64
|
-
|
|
64
|
+
loaderContext?: (opts: {
|
|
65
|
+
search: TFullSearchSchema;
|
|
66
|
+
}) => TLoaderContext;
|
|
65
67
|
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
66
|
-
beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams,
|
|
68
|
+
beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
|
|
67
69
|
} : {
|
|
68
|
-
beforeLoad: BeforeLoadFn<TParentRoute, TAllParams,
|
|
69
|
-
}) &
|
|
70
|
+
beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
|
|
71
|
+
}) & {
|
|
72
|
+
loader?: LoaderFn<TLoader, TAllParams, NoInfer<TLoaderContext>, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
|
|
73
|
+
} & ([TLoader] extends [never] ? {
|
|
70
74
|
loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.';
|
|
71
75
|
} : {}) & ({
|
|
72
76
|
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
@@ -75,21 +79,13 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
|
|
|
75
79
|
stringifyParams?: never;
|
|
76
80
|
parseParams?: never;
|
|
77
81
|
});
|
|
78
|
-
type BeforeLoadFn<TParentRoute, TAllParams,
|
|
79
|
-
params: TAllParams;
|
|
80
|
-
routeSearch: TSearchSchema;
|
|
81
|
-
search: TFullSearchSchema;
|
|
82
|
+
type BeforeLoadFn<TParentRoute, TAllParams, TParentContext, TLoaderContext, TRouteContext> = (opts: {
|
|
82
83
|
abortController: AbortController;
|
|
83
84
|
preload: boolean;
|
|
84
|
-
|
|
85
|
-
context
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
context: TAllParentContext;
|
|
89
|
-
parentContext: TParentContext;
|
|
90
|
-
})) => Promise<TRouteContext> | TRouteContext | void;
|
|
91
|
-
export type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TAllContext extends AnyContext> = MetaOptions & {
|
|
92
|
-
key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>;
|
|
85
|
+
params: TAllParams;
|
|
86
|
+
context: Expand<TParentContext & TLoaderContext>;
|
|
87
|
+
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
88
|
+
export type UpdatableRouteOptions<TLoader, TSearchSchema extends Record<string, any>, TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TRouteContext extends Record<string, any>, TAllContext extends Record<string, any>> = MetaOptions & {
|
|
93
89
|
caseSensitive?: boolean;
|
|
94
90
|
wrapInSuspense?: boolean;
|
|
95
91
|
component?: RegisteredRouteComponent<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
@@ -120,39 +116,26 @@ export type DefinedPathParamWarning = 'Path params cannot be redefined by child
|
|
|
120
116
|
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
121
117
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
122
118
|
};
|
|
123
|
-
export type LoaderFn<TLoader = unknown,
|
|
119
|
+
export type LoaderFn<TLoader = unknown, TAllParams = {}, TLoaderContext extends Record<string, any> = AnyContext, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> = (match: LoaderContext<TAllParams, TLoaderContext, TAllContext, TRouteContext> & {
|
|
124
120
|
parentMatchPromise?: Promise<void>;
|
|
125
121
|
}) => Promise<TLoader> | TLoader;
|
|
126
|
-
export
|
|
127
|
-
params: TAllParams;
|
|
128
|
-
search: TFullSearchSchema;
|
|
129
|
-
}) => any;
|
|
130
|
-
export interface LoaderContext<TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams = {}, TContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
131
|
-
params: TAllParams;
|
|
132
|
-
routeSearch: TSearchSchema;
|
|
133
|
-
search: TFullSearchSchema;
|
|
122
|
+
export interface LoaderContext<TAllParams = {}, TLoaderContext = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
|
|
134
123
|
abortController: AbortController;
|
|
135
124
|
preload: boolean;
|
|
136
|
-
|
|
137
|
-
context: TAllContext
|
|
125
|
+
params: TAllParams;
|
|
126
|
+
context: DeepMergeAll<[TAllContext, TLoaderContext, TRouteContext]>;
|
|
138
127
|
}
|
|
139
|
-
export type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, Route>) => void;
|
|
140
128
|
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
141
129
|
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
142
130
|
id: infer TParentId extends string;
|
|
143
131
|
} ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId> : RootRouteId;
|
|
144
132
|
export type InferFullSearchSchema<TRoute> = TRoute extends {
|
|
145
|
-
isRoot: true;
|
|
146
|
-
types: {
|
|
147
|
-
searchSchema: infer TSearchSchema;
|
|
148
|
-
};
|
|
149
|
-
} ? TSearchSchema : TRoute extends {
|
|
150
133
|
types: {
|
|
151
134
|
fullSearchSchema: infer TFullSearchSchema;
|
|
152
135
|
};
|
|
153
136
|
} ? TFullSearchSchema : {};
|
|
154
|
-
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = InferFullSearchSchema<TParentRoute
|
|
155
|
-
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
137
|
+
export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
|
|
138
|
+
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
156
139
|
}
|
|
157
140
|
export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
|
|
158
141
|
export type UseLoaderResult<T> = T;
|
|
@@ -169,6 +152,7 @@ export type RouteConstraints = {
|
|
|
169
152
|
TFullPath: string;
|
|
170
153
|
TCustomId: string;
|
|
171
154
|
TId: string;
|
|
155
|
+
TLoaderContext: Record<string, any>;
|
|
172
156
|
TSearchSchema: AnySearchSchema;
|
|
173
157
|
TFullSearchSchema: AnySearchSchema;
|
|
174
158
|
TParams: Record<string, any>;
|
|
@@ -181,7 +165,7 @@ export type RouteConstraints = {
|
|
|
181
165
|
TChildren: unknown;
|
|
182
166
|
TRouteTree: AnyRoute;
|
|
183
167
|
};
|
|
184
|
-
export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
168
|
+
export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoaderContext extends RouteConstraints['TLoaderContext'] = AnyContext, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
185
169
|
types: {
|
|
186
170
|
parentRoute: TParentRoute;
|
|
187
171
|
path: TPath;
|
|
@@ -203,7 +187,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
203
187
|
routerContext: TRouterContext;
|
|
204
188
|
};
|
|
205
189
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
206
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader,
|
|
190
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext>;
|
|
207
191
|
parentRoute: TParentRoute;
|
|
208
192
|
id: TId;
|
|
209
193
|
path: TPath;
|
|
@@ -213,22 +197,22 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
213
197
|
originalIndex?: number;
|
|
214
198
|
router?: AnyRouter;
|
|
215
199
|
rank: number;
|
|
216
|
-
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader,
|
|
200
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
|
|
217
201
|
init: (opts: {
|
|
218
202
|
originalIndex: number;
|
|
219
203
|
router: AnyRouter;
|
|
220
204
|
}) => void;
|
|
221
|
-
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
|
|
205
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
|
|
222
206
|
update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>) => this;
|
|
223
207
|
static __onInit: (route: any) => void;
|
|
224
208
|
}
|
|
225
209
|
export type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
226
210
|
export declare class RouterContext<TRouterContext extends {}> {
|
|
227
211
|
constructor();
|
|
228
|
-
createRootRoute: <TLoader = unknown, TSearchSchema extends
|
|
212
|
+
createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
|
|
229
213
|
}
|
|
230
|
-
export declare class RootRoute<TLoader = unknown, TSearchSchema extends
|
|
231
|
-
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '',
|
|
214
|
+
export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>, TRouterContext, any, any> {
|
|
215
|
+
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
232
216
|
}
|
|
233
217
|
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
234
218
|
type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyRoute, Route } from './route';
|
|
2
|
-
import { UnionToIntersection } from './utils';
|
|
2
|
+
import { Expand, UnionToIntersection } from './utils';
|
|
3
3
|
export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
|
|
4
|
-
export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
|
|
4
|
+
export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
|
|
5
5
|
[TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
|
|
6
6
|
}[string] : never : never;
|
|
7
7
|
export type RoutesById<TRouteTree extends AnyRoute> = {
|
|
@@ -18,5 +18,5 @@ export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<ParseRoute
|
|
|
18
18
|
fullPath: TPath;
|
|
19
19
|
}>;
|
|
20
20
|
export type RoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree>['fullPath'] | '/';
|
|
21
|
-
export type FullSearchSchema<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']> & {}
|
|
22
|
-
export type AllParams<TRouteTree extends AnyRoute> = UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']
|
|
21
|
+
export type FullSearchSchema<TRouteTree extends AnyRoute> = Partial<Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['fullSearchSchema']> & {}>>;
|
|
22
|
+
export type AllParams<TRouteTree extends AnyRoute> = Expand<UnionToIntersection<ParseRoute<TRouteTree>['types']['allParams']>>;
|
package/build/types/router.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type HydrationCtx = {
|
|
|
40
40
|
};
|
|
41
41
|
export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id']> {
|
|
42
42
|
id: string;
|
|
43
|
-
|
|
43
|
+
loaderContext?: any;
|
|
44
44
|
routeId: TRouteId;
|
|
45
45
|
pathname: string;
|
|
46
46
|
params: RouteById<TRouteTree, TRouteId>['types']['allParams'];
|
|
@@ -56,7 +56,6 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
|
|
|
56
56
|
loaderData: RouteById<TRouteTree, TRouteId>['types']['loader'];
|
|
57
57
|
loadPromise?: Promise<void>;
|
|
58
58
|
__resolveLoadPromise?: () => void;
|
|
59
|
-
routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext'];
|
|
60
59
|
context: RouteById<TRouteTree, TRouteId>['types']['context'];
|
|
61
60
|
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
|
|
62
61
|
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
package/build/types/utils.d.ts
CHANGED
|
@@ -15,6 +15,13 @@ export type Expand<T> = T extends object ? T extends infer O ? {
|
|
|
15
15
|
[K in keyof O]: O[K];
|
|
16
16
|
} : never : T;
|
|
17
17
|
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
18
|
+
export type DeepMerge<A, B> = {
|
|
19
|
+
[K in keyof (A & B)]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
20
|
+
} & (A extends Record<string, any> ? Pick<A, Exclude<keyof A, keyof B>> : never) & (B extends Record<string, any> ? Pick<B, Exclude<keyof B, keyof A>> : never);
|
|
21
|
+
export type DeepMergeAll<T extends any[]> = T extends [
|
|
22
|
+
infer Left,
|
|
23
|
+
...infer Rest
|
|
24
|
+
] ? Rest extends any[] ? DeepMerge<Left, DeepMergeAll<Rest>> : Left : {};
|
|
18
25
|
export type Values<O> = O[ValueKeys<O>];
|
|
19
26
|
export type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
20
27
|
export type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
@@ -1181,12 +1181,19 @@
|
|
|
1181
1181
|
});
|
|
1182
1182
|
const matches = matchedRoutes.map((route, index) => {
|
|
1183
1183
|
const interpolatedPath = interpolatePath(route.path, routeParams);
|
|
1184
|
-
const
|
|
1185
|
-
params: routeParams,
|
|
1184
|
+
const loaderContext = route.options.loaderContext ? route.options.loaderContext({
|
|
1186
1185
|
search: locationSearch
|
|
1187
|
-
})
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1186
|
+
}) : undefined;
|
|
1187
|
+
const matchId = JSON.stringify([interpolatePath(route.id, routeParams, true), loaderContext].filter(d => d !== undefined), (key, value) => {
|
|
1188
|
+
if (typeof value === 'function') {
|
|
1189
|
+
console.info(route);
|
|
1190
|
+
invariant(false, `Cannot return functions and other non-serializable values from routeOptions.loaderContext! Please use routeOptions.beforeLoad to do this. Route info is logged above 👆`);
|
|
1191
|
+
}
|
|
1192
|
+
if (typeof value === 'object' && value !== null) {
|
|
1193
|
+
return Object.fromEntries(Object.keys(value).sort().map(key => [key, value[key]]));
|
|
1194
|
+
}
|
|
1195
|
+
return value;
|
|
1196
|
+
});
|
|
1190
1197
|
|
|
1191
1198
|
// Waste not, want not. If we already have a match for this route,
|
|
1192
1199
|
// reuse it. This is important for layout routes, which might stick
|
|
@@ -1202,7 +1209,7 @@
|
|
|
1202
1209
|
const hasLoaders = !!(route.options.loader || componentTypes.some(d => route.options[d]?.preload));
|
|
1203
1210
|
const routeMatch = {
|
|
1204
1211
|
id: matchId,
|
|
1205
|
-
|
|
1212
|
+
loaderContext,
|
|
1206
1213
|
routeId: route.id,
|
|
1207
1214
|
params: routeParams,
|
|
1208
1215
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
@@ -1219,7 +1226,6 @@
|
|
|
1219
1226
|
searchError: undefined,
|
|
1220
1227
|
loaderData: undefined,
|
|
1221
1228
|
loadPromise: Promise.resolve(),
|
|
1222
|
-
routeContext: undefined,
|
|
1223
1229
|
context: undefined,
|
|
1224
1230
|
abortController: new AbortController(),
|
|
1225
1231
|
fetchedAt: 0
|
|
@@ -1276,7 +1282,6 @@
|
|
|
1276
1282
|
...s,
|
|
1277
1283
|
routeSearch: match.routeSearch,
|
|
1278
1284
|
search: match.search,
|
|
1279
|
-
routeContext: match.routeContext,
|
|
1280
1285
|
context: match.context,
|
|
1281
1286
|
error: match.error,
|
|
1282
1287
|
paramsError: match.paramsError,
|
|
@@ -1321,21 +1326,25 @@
|
|
|
1321
1326
|
handleError(match.searchError, 'VALIDATE_SEARCH');
|
|
1322
1327
|
}
|
|
1323
1328
|
let didError = false;
|
|
1329
|
+
const parentContext = parentMatch?.context ?? this?.options.context ?? {};
|
|
1324
1330
|
try {
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1331
|
+
const beforeLoadContext = (await route.options.beforeLoad?.({
|
|
1332
|
+
abortController: match.abortController,
|
|
1333
|
+
params: match.params,
|
|
1327
1334
|
preload: !!opts?.preload,
|
|
1328
|
-
|
|
1329
|
-
|
|
1335
|
+
context: {
|
|
1336
|
+
...parentContext,
|
|
1337
|
+
...match.loaderContext
|
|
1338
|
+
}
|
|
1330
1339
|
})) ?? {};
|
|
1331
1340
|
const context = {
|
|
1332
|
-
...
|
|
1333
|
-
...
|
|
1341
|
+
...parentContext,
|
|
1342
|
+
...match.loaderContext,
|
|
1343
|
+
...beforeLoadContext
|
|
1334
1344
|
};
|
|
1335
1345
|
this.setRouteMatch(match.id, s => ({
|
|
1336
1346
|
...s,
|
|
1337
|
-
context
|
|
1338
|
-
routeContext
|
|
1347
|
+
context
|
|
1339
1348
|
}));
|
|
1340
1349
|
} catch (err) {
|
|
1341
1350
|
handleError(err, 'BEFORE_LOAD');
|
|
@@ -1389,9 +1398,11 @@
|
|
|
1389
1398
|
}
|
|
1390
1399
|
}));
|
|
1391
1400
|
const loaderPromise = route.options.loader?.({
|
|
1392
|
-
|
|
1401
|
+
params: match.params,
|
|
1393
1402
|
preload: !!opts?.preload,
|
|
1394
|
-
parentMatchPromise
|
|
1403
|
+
parentMatchPromise,
|
|
1404
|
+
abortController: match.abortController,
|
|
1405
|
+
context: match.context
|
|
1395
1406
|
});
|
|
1396
1407
|
const [_, loader] = await Promise.all([componentsPromise, loaderPromise]);
|
|
1397
1408
|
if (latestPromise = checkLatest()) return await latestPromise;
|