@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
|
@@ -14,7 +14,7 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
|
|
|
14
14
|
updatedAt: number;
|
|
15
15
|
loadPromise?: Promise<void>;
|
|
16
16
|
__resolveLoadPromise?: () => void;
|
|
17
|
-
|
|
17
|
+
context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
|
|
18
18
|
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema'];
|
|
19
19
|
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
|
20
20
|
fetchedAt: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRoute, ResolveFullPath,
|
|
1
|
+
import { AnyRoute, ResolveFullPath, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, AnyPathParams, RootRouteId, TrimPathLeft, RouteConstraints } from './route';
|
|
2
2
|
import { Assign, Expand, IsAny } from './utils';
|
|
3
3
|
export interface FileRoutesByPath {
|
|
4
4
|
}
|
|
@@ -12,6 +12,21 @@ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends strin
|
|
|
12
12
|
export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
|
|
13
13
|
path: TFilePath;
|
|
14
14
|
constructor(path: TFilePath);
|
|
15
|
-
createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = Expand<Assign<import("./route").InferFullSearchSchema<TParentRoute>, TSearchSchema>>, TParams extends Record<string, any> = (TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never) extends never ? AnyPathParams : Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never, string>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>,
|
|
15
|
+
createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = Expand<Assign<import("./route").InferFullSearchSchema<TParentRoute>, TSearchSchema>>, TParams extends Record<string, any> = (TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never) extends never ? AnyPathParams : Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L : never : never : never, string>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext>, "id" | "path" | "getParentRoute"> & {
|
|
16
|
+
meta?: import("./route").RouteMeta | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
caseSensitive?: boolean | undefined;
|
|
19
|
+
wrapInSuspense?: boolean | undefined;
|
|
20
|
+
component?: import("./react").RouteComponent<TFullSearchSchema, TAllParams, TContext> | undefined;
|
|
21
|
+
errorComponent?: import("./react").ErrorRouteComponent<TFullSearchSchema, TAllParams, {}> | undefined;
|
|
22
|
+
pendingComponent?: import("./react").PendingRouteComponent<TFullSearchSchema, TAllParams, TContext> | undefined;
|
|
23
|
+
preSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
24
|
+
postSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
|
|
25
|
+
onError?: ((err: any) => void) | undefined;
|
|
26
|
+
onEnter?: ((match: import("./RouteMatch").AnyRouteMatch) => void) | undefined;
|
|
27
|
+
onTransition?: ((match: import("./RouteMatch").AnyRouteMatch) => void) | undefined;
|
|
28
|
+
onLeave?: ((match: import("./RouteMatch").AnyRouteMatch) => void) | undefined;
|
|
29
|
+
reloadOnWindowFocus?: boolean | undefined;
|
|
30
|
+
}) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TChildren, TRouteTree>;
|
|
16
31
|
}
|
|
17
32
|
export {};
|
package/build/types/react.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type RouteProps<TFullSearchSchema extends Record<string, any> = AnySearch
|
|
|
10
10
|
useMatch: <TSelected = TAllContext>(opts?: {
|
|
11
11
|
select?: (search: TAllContext) => TSelected;
|
|
12
12
|
}) => TSelected;
|
|
13
|
-
|
|
13
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
14
14
|
select?: (search: TAllContext) => TSelected;
|
|
15
15
|
}) => TSelected;
|
|
16
16
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
@@ -66,7 +66,7 @@ export declare function Navigate<TRouteTree extends AnyRoute = RegisteredRouter[
|
|
|
66
66
|
export declare const matchesContext: React.Context<RouteMatch<AnyRoute, any>[]>;
|
|
67
67
|
export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
68
68
|
router: Router<TRouteTree>;
|
|
69
|
-
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['
|
|
69
|
+
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
|
|
70
70
|
};
|
|
71
71
|
export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): RouterContext<TRouteTree>;
|
|
72
72
|
export declare function useRouterState<TSelected = RouterState<RegisteredRouter['routeTree']>>(opts?: {
|
|
@@ -86,8 +86,8 @@ export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter[
|
|
|
86
86
|
select?: (match: TRouteMatchState) => TSelected;
|
|
87
87
|
}): TStrict extends true ? TRouteMatchState : TRouteMatchState | undefined;
|
|
88
88
|
export type RouteFromIdOrRoute<T, TRouteTree extends AnyRoute = RegisteredRouter['routeTree']> = T extends ParseRoute<TRouteTree> ? T : T extends RouteIds<TRouteTree> ? RoutesById<TRouteTree>[T] : T extends string ? RouteIds<TRouteTree> : never;
|
|
89
|
-
export declare function
|
|
90
|
-
select?: (search:
|
|
89
|
+
export declare function useRouteContext<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'], TSelected = TRouteContext>(opts: StrictOrFrom<TFrom> & {
|
|
90
|
+
select?: (search: TRouteContext) => TSelected;
|
|
91
91
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
92
92
|
export declare function useSearch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TSearch = RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'], TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
93
93
|
select?: (search: TSearch) => TSelected;
|
package/build/types/route.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type RootRouteId = typeof rootRouteId;
|
|
|
10
10
|
export type AnyPathParams = {};
|
|
11
11
|
export type AnySearchSchema = {};
|
|
12
12
|
export type AnyContext = {};
|
|
13
|
+
export interface RouteContext {
|
|
14
|
+
}
|
|
13
15
|
export interface RouteMeta {
|
|
14
16
|
}
|
|
15
17
|
export type PreloadableObj = {
|
|
@@ -21,17 +23,22 @@ export type RoutePathOptions<TCustomId, TPath> = {
|
|
|
21
23
|
id: TCustomId;
|
|
22
24
|
};
|
|
23
25
|
export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
|
|
24
|
-
export type
|
|
26
|
+
export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
27
|
+
meta?: RouteMeta;
|
|
28
|
+
} : {
|
|
29
|
+
meta: RouteMeta;
|
|
30
|
+
};
|
|
31
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & NoInfer<UpdatableRouteOptions<TFullSearchSchema, TAllParams, TAllContext>>;
|
|
25
32
|
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
26
|
-
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>,
|
|
33
|
+
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
|
|
27
34
|
getParentRoute: () => TParentRoute;
|
|
28
35
|
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
29
|
-
} & (keyof PickRequired<
|
|
30
|
-
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams,
|
|
36
|
+
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
37
|
+
beforeLoad?: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
31
38
|
} : {
|
|
32
|
-
beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams,
|
|
39
|
+
beforeLoad: BeforeLoadFn<TFullSearchSchema, TParentRoute, TAllParams, TRouteContext>;
|
|
33
40
|
}) & {
|
|
34
|
-
load?: RouteLoadFn<TAllParams, TFullSearchSchema, NoInfer<TAllContext>, NoInfer<
|
|
41
|
+
load?: RouteLoadFn<TAllParams, TFullSearchSchema, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
|
|
35
42
|
} & ({
|
|
36
43
|
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
37
44
|
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
|
|
@@ -39,16 +46,16 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
|
|
|
39
46
|
stringifyParams?: never;
|
|
40
47
|
parseParams?: never;
|
|
41
48
|
});
|
|
42
|
-
type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute extends AnyRoute, TAllParams,
|
|
49
|
+
type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute extends AnyRoute, TAllParams, TRouteContext> = (opts: {
|
|
43
50
|
search: TFullSearchSchema;
|
|
44
51
|
abortController: AbortController;
|
|
45
52
|
preload: boolean;
|
|
46
53
|
params: TAllParams;
|
|
47
|
-
|
|
54
|
+
context: TParentRoute['types']['allContext'];
|
|
48
55
|
location: ParsedLocation;
|
|
49
56
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
50
|
-
}) => Promise<
|
|
51
|
-
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext> = {
|
|
57
|
+
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
58
|
+
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext> = MetaOptions & {
|
|
52
59
|
caseSensitive?: boolean;
|
|
53
60
|
wrapInSuspense?: boolean;
|
|
54
61
|
component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
|
|
@@ -76,15 +83,15 @@ export type DefinedPathParamWarning = 'Path params cannot be redefined by child
|
|
|
76
83
|
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
77
84
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
78
85
|
};
|
|
79
|
-
export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext,
|
|
86
|
+
export type RouteLoadFn<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> = (match: LoadFnContext<TAllParams, TFullSearchSchema, TAllContext, TRouteContext> & {
|
|
80
87
|
parentMatchPromise?: Promise<void>;
|
|
81
88
|
}) => any;
|
|
82
|
-
export interface LoadFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext,
|
|
89
|
+
export interface LoadFnContext<TAllParams = {}, TFullSearchSchema extends Record<string, any> = {}, TAllContext extends Record<string, any> = AnyContext, TRouteContext extends Record<string, any> = AnyContext> {
|
|
83
90
|
abortController: AbortController;
|
|
84
91
|
preload: boolean;
|
|
85
92
|
params: TAllParams;
|
|
86
93
|
search: TFullSearchSchema;
|
|
87
|
-
|
|
94
|
+
context: Expand<Assign<TAllContext, TRouteContext>>;
|
|
88
95
|
location: ParsedLocation<TFullSearchSchema>;
|
|
89
96
|
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
90
97
|
}
|
|
@@ -119,16 +126,16 @@ export type RouteConstraints = {
|
|
|
119
126
|
TParams: Record<string, any>;
|
|
120
127
|
TAllParams: Record<string, any>;
|
|
121
128
|
TParentContext: AnyContext;
|
|
122
|
-
|
|
129
|
+
TRouteContext: RouteContext;
|
|
123
130
|
TAllContext: AnyContext;
|
|
124
|
-
|
|
131
|
+
TRouterContext: AnyContext;
|
|
125
132
|
TChildren: unknown;
|
|
126
133
|
TRouteTree: AnyRoute;
|
|
127
134
|
};
|
|
128
|
-
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>, 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>,
|
|
135
|
+
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>, 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>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
129
136
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
130
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
131
|
-
test: Expand<Assign<IsAny<TParentRoute['types']['
|
|
137
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>;
|
|
138
|
+
test: Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>;
|
|
132
139
|
parentRoute: TParentRoute;
|
|
133
140
|
id: TId;
|
|
134
141
|
path: TPath;
|
|
@@ -138,7 +145,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
138
145
|
originalIndex?: number;
|
|
139
146
|
router?: AnyRouter;
|
|
140
147
|
rank: number;
|
|
141
|
-
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
148
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>);
|
|
142
149
|
types: {
|
|
143
150
|
parentRoute: TParentRoute;
|
|
144
151
|
path: TPath;
|
|
@@ -150,23 +157,23 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
150
157
|
fullSearchSchema: TFullSearchSchema;
|
|
151
158
|
params: TParams;
|
|
152
159
|
allParams: TAllParams;
|
|
153
|
-
|
|
154
|
-
|
|
160
|
+
routeContext: TRouteContext;
|
|
161
|
+
allContext: TAllContext;
|
|
155
162
|
children: TChildren;
|
|
156
163
|
routeTree: TRouteTree;
|
|
157
|
-
|
|
164
|
+
routerContext: TRouterContext;
|
|
158
165
|
};
|
|
159
166
|
init: (opts: {
|
|
160
167
|
originalIndex: number;
|
|
161
168
|
}) => void;
|
|
162
|
-
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
163
|
-
update: (options: UpdatableRouteOptions<TFullSearchSchema, TAllParams, Expand<Assign<IsAny<TParentRoute['types']['
|
|
169
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
|
|
170
|
+
update: (options: UpdatableRouteOptions<TFullSearchSchema, TAllParams, Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>>) => this;
|
|
164
171
|
static __onInit: (route: any) => void;
|
|
165
|
-
useMatch: <TSelected =
|
|
166
|
-
select?: ((search:
|
|
172
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
173
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
167
174
|
} | undefined) => TSelected;
|
|
168
|
-
|
|
169
|
-
select?: ((search:
|
|
175
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
176
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
170
177
|
} | undefined) => TSelected;
|
|
171
178
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
172
179
|
select?: ((search: TFullSearchSchema) => TSelected) | undefined;
|
|
@@ -176,11 +183,8 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
176
183
|
} | undefined) => TSelected;
|
|
177
184
|
}
|
|
178
185
|
export type AnyRootRoute = RootRoute<any, any, any>;
|
|
179
|
-
export declare
|
|
180
|
-
|
|
181
|
-
createRootRoute: <TSearchSchema extends Record<string, any> = {}, TRouteMeta extends RouteMeta = RouteMeta>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteMeta, Assign<TRouterMeta, TRouteMeta>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteMeta, TRouterMeta>;
|
|
182
|
-
}
|
|
183
|
-
export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteMeta extends RouteMeta = RouteMeta, TRouterMeta extends {} = {}> extends Route<any, // TParentRoute
|
|
186
|
+
export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchema, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchema, TRouteContext, TRouterContext>;
|
|
187
|
+
export declare class RootRoute<TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, // TParentRoute
|
|
184
188
|
'/', // TPath
|
|
185
189
|
'/', // TFullPath
|
|
186
190
|
string, // TCustomId
|
|
@@ -189,9 +193,9 @@ TSearchSchema, // TSearchSchema
|
|
|
189
193
|
TSearchSchema, // TFullSearchSchema
|
|
190
194
|
{}, // TParams
|
|
191
195
|
{}, // TAllParams
|
|
192
|
-
|
|
193
|
-
Expand<Assign<
|
|
194
|
-
|
|
196
|
+
TRouteContext, // TRouteContext
|
|
197
|
+
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
198
|
+
TRouterContext, // TRouterContext
|
|
195
199
|
any, // TChildren
|
|
196
200
|
any> {
|
|
197
201
|
constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
|
|
@@ -201,8 +205,8 @@ any> {
|
|
|
201
205
|
TSearchSchema, // TFullSearchSchema
|
|
202
206
|
{}, // TParams
|
|
203
207
|
{}, // TAllParams
|
|
204
|
-
|
|
205
|
-
Assign<
|
|
208
|
+
TRouteContext, // TRouteContext
|
|
209
|
+
Assign<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
206
210
|
}
|
|
207
211
|
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
208
212
|
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;
|
package/build/types/router.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ export type HydrationCtx = {
|
|
|
25
25
|
router: DehydratedRouter;
|
|
26
26
|
payload: Record<string, any>;
|
|
27
27
|
};
|
|
28
|
-
export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends TRouteTree['types']['
|
|
29
|
-
|
|
28
|
+
export type RouterContextOptions<TRouteTree extends AnyRoute> = AnyContext extends TRouteTree['types']['routerContext'] ? {
|
|
29
|
+
context?: TRouteTree['types']['routerContext'];
|
|
30
30
|
} : {
|
|
31
|
-
|
|
31
|
+
context: TRouteTree['types']['routerContext'];
|
|
32
32
|
};
|
|
33
33
|
export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
34
34
|
history?: RouterHistory;
|
|
@@ -49,7 +49,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
|
|
|
49
49
|
route: AnyRoute;
|
|
50
50
|
router: AnyRouter;
|
|
51
51
|
}) => void;
|
|
52
|
-
|
|
52
|
+
context?: TRouteTree['types']['routerContext'];
|
|
53
53
|
routeMasks?: RouteMask<TRouteTree>[];
|
|
54
54
|
unmaskOnReload?: boolean;
|
|
55
55
|
}
|
|
@@ -108,7 +108,7 @@ export type RouterListener<TRouterEvent extends RouterEvent> = {
|
|
|
108
108
|
fn: ListenerFn<TRouterEvent>;
|
|
109
109
|
};
|
|
110
110
|
export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
111
|
-
options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | '
|
|
111
|
+
options: PickAsRequired<RouterOptions<TRouteTree, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
112
112
|
routeTree: TRouteTree;
|
|
113
113
|
constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
|
|
114
114
|
subscribers: Set<RouterListener<RouterEvent>>;
|
|
@@ -813,7 +813,7 @@
|
|
|
813
813
|
constructor(options) {
|
|
814
814
|
this.options = {
|
|
815
815
|
defaultPreloadDelay: 50,
|
|
816
|
-
|
|
816
|
+
context: undefined,
|
|
817
817
|
...options,
|
|
818
818
|
stringifySearch: options?.stringifySearch ?? defaultStringifySearch,
|
|
819
819
|
parseSearch: options?.parseSearch ?? defaultParseSearch
|
|
@@ -1017,9 +1017,9 @@
|
|
|
1017
1017
|
const options = {
|
|
1018
1018
|
...router.options,
|
|
1019
1019
|
...rest,
|
|
1020
|
-
|
|
1021
|
-
...router.options.
|
|
1022
|
-
...rest?.
|
|
1020
|
+
context: {
|
|
1021
|
+
...router.options.context,
|
|
1022
|
+
...rest?.context
|
|
1023
1023
|
}
|
|
1024
1024
|
};
|
|
1025
1025
|
const history = React__namespace.useState(() => options.history ?? createBrowserHistory())[0];
|
|
@@ -1228,16 +1228,16 @@
|
|
|
1228
1228
|
paramsError: parseErrors[index],
|
|
1229
1229
|
searchError: undefined,
|
|
1230
1230
|
loadPromise: Promise.resolve(),
|
|
1231
|
-
|
|
1231
|
+
context: undefined,
|
|
1232
1232
|
abortController: new AbortController(),
|
|
1233
1233
|
fetchedAt: 0
|
|
1234
1234
|
};
|
|
1235
1235
|
return routeMatch;
|
|
1236
1236
|
});
|
|
1237
1237
|
|
|
1238
|
-
// Take each match and resolve its search params and
|
|
1238
|
+
// Take each match and resolve its search params and context
|
|
1239
1239
|
// This has to happen after the matches are created or found
|
|
1240
|
-
// so that we can use the parent match's search params and
|
|
1240
|
+
// so that we can use the parent match's search params and context
|
|
1241
1241
|
matches.forEach((match, i) => {
|
|
1242
1242
|
const parentMatch = matches[i - 1];
|
|
1243
1243
|
const route = looseRoutesById[match.routeId];
|
|
@@ -1491,13 +1491,13 @@
|
|
|
1491
1491
|
if (match.searchError) {
|
|
1492
1492
|
handleError(match.searchError, 'VALIDATE_SEARCH');
|
|
1493
1493
|
}
|
|
1494
|
-
const
|
|
1495
|
-
const
|
|
1494
|
+
const parentContext = parentMatch?.context ?? options.context ?? {};
|
|
1495
|
+
const beforeLoadContext = (await route.options.beforeLoad?.({
|
|
1496
1496
|
search: match.search,
|
|
1497
1497
|
abortController: match.abortController,
|
|
1498
1498
|
params: match.params,
|
|
1499
1499
|
preload: !!preload,
|
|
1500
|
-
|
|
1500
|
+
context: parentContext,
|
|
1501
1501
|
location: state.location,
|
|
1502
1502
|
// TODO: This might need to be latestLocationRef.current...?
|
|
1503
1503
|
navigate: opts => navigate({
|
|
@@ -1505,13 +1505,13 @@
|
|
|
1505
1505
|
from: match.pathname
|
|
1506
1506
|
})
|
|
1507
1507
|
})) ?? {};
|
|
1508
|
-
const
|
|
1509
|
-
...
|
|
1510
|
-
...
|
|
1508
|
+
const context = {
|
|
1509
|
+
...parentContext,
|
|
1510
|
+
...beforeLoadContext
|
|
1511
1511
|
};
|
|
1512
1512
|
matches[index] = match = {
|
|
1513
1513
|
...match,
|
|
1514
|
-
|
|
1514
|
+
context: replaceEqualDeep(match.context, context)
|
|
1515
1515
|
};
|
|
1516
1516
|
} catch (err) {
|
|
1517
1517
|
handleError(err, 'BEFORE_LOAD');
|
|
@@ -1557,7 +1557,7 @@
|
|
|
1557
1557
|
preload: !!preload,
|
|
1558
1558
|
parentMatchPromise,
|
|
1559
1559
|
abortController: match.abortController,
|
|
1560
|
-
|
|
1560
|
+
context: match.context,
|
|
1561
1561
|
location: state.location,
|
|
1562
1562
|
navigate: opts => navigate({
|
|
1563
1563
|
...opts,
|
|
@@ -2112,10 +2112,10 @@
|
|
|
2112
2112
|
});
|
|
2113
2113
|
return matchSelection;
|
|
2114
2114
|
}
|
|
2115
|
-
function
|
|
2115
|
+
function useRouteContext(opts) {
|
|
2116
2116
|
return useMatch({
|
|
2117
2117
|
...opts,
|
|
2118
|
-
select: match => opts?.select ? opts.select(match.
|
|
2118
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
2119
2119
|
});
|
|
2120
2120
|
}
|
|
2121
2121
|
function useSearch(opts) {
|
|
@@ -2192,7 +2192,7 @@
|
|
|
2192
2192
|
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
2193
2193
|
...props,
|
|
2194
2194
|
useMatch: route.useMatch,
|
|
2195
|
-
|
|
2195
|
+
useRouteContext: route.useRouteContext,
|
|
2196
2196
|
useSearch: route.useSearch,
|
|
2197
2197
|
useParams: route.useParams
|
|
2198
2198
|
});
|
|
@@ -2248,7 +2248,7 @@
|
|
|
2248
2248
|
return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
|
|
2249
2249
|
...props,
|
|
2250
2250
|
useMatch: route.useMatch,
|
|
2251
|
-
|
|
2251
|
+
useRouteContext: route.useRouteContext,
|
|
2252
2252
|
useSearch: route.useSearch,
|
|
2253
2253
|
useParams: route.useParams
|
|
2254
2254
|
});
|
|
@@ -2258,7 +2258,7 @@
|
|
|
2258
2258
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
2259
2259
|
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
2260
2260
|
useMatch: route.useMatch,
|
|
2261
|
-
|
|
2261
|
+
useRouteContext: route.useRouteContext,
|
|
2262
2262
|
useSearch: route.useSearch,
|
|
2263
2263
|
useParams: route.useParams
|
|
2264
2264
|
})
|
|
@@ -2291,7 +2291,7 @@
|
|
|
2291
2291
|
if (comp) {
|
|
2292
2292
|
return /*#__PURE__*/React__namespace.createElement(comp, {
|
|
2293
2293
|
useMatch: route.useMatch,
|
|
2294
|
-
|
|
2294
|
+
useRouteContext: route.useRouteContext,
|
|
2295
2295
|
useSearch: route.useSearch,
|
|
2296
2296
|
useParams: route.useParams
|
|
2297
2297
|
});
|
|
@@ -2467,14 +2467,8 @@
|
|
|
2467
2467
|
|
|
2468
2468
|
const rootRouteId = '__root__';
|
|
2469
2469
|
|
|
2470
|
-
// export type MetaOptions = keyof PickRequired<RouteMeta> extends never
|
|
2471
|
-
// ? {
|
|
2472
|
-
// meta?: RouteMeta
|
|
2473
|
-
// }
|
|
2474
|
-
// : {
|
|
2475
|
-
// meta: RouteMeta
|
|
2476
|
-
// }
|
|
2477
2470
|
// The parse type here allows a zod schema to be passed directly to the validator
|
|
2471
|
+
|
|
2478
2472
|
class Route {
|
|
2479
2473
|
// Set up in this.init()
|
|
2480
2474
|
|
|
@@ -2538,11 +2532,11 @@
|
|
|
2538
2532
|
from: this.id
|
|
2539
2533
|
});
|
|
2540
2534
|
};
|
|
2541
|
-
|
|
2535
|
+
useRouteContext = opts => {
|
|
2542
2536
|
return useMatch({
|
|
2543
2537
|
...opts,
|
|
2544
2538
|
from: this.id,
|
|
2545
|
-
select: d => opts?.select ? opts.select(d.
|
|
2539
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
2546
2540
|
});
|
|
2547
2541
|
};
|
|
2548
2542
|
useSearch = opts => {
|
|
@@ -2558,9 +2552,8 @@
|
|
|
2558
2552
|
});
|
|
2559
2553
|
};
|
|
2560
2554
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
createRootRoute = options => {
|
|
2555
|
+
function rootRouteWithContext() {
|
|
2556
|
+
return options => {
|
|
2564
2557
|
return new RootRoute(options);
|
|
2565
2558
|
};
|
|
2566
2559
|
}
|
|
@@ -2598,7 +2591,6 @@
|
|
|
2598
2591
|
exports.RootRoute = RootRoute;
|
|
2599
2592
|
exports.Route = Route;
|
|
2600
2593
|
exports.Router = Router;
|
|
2601
|
-
exports.RouterMeta = RouterMeta;
|
|
2602
2594
|
exports.RouterProvider = RouterProvider;
|
|
2603
2595
|
exports.SearchParamError = SearchParamError;
|
|
2604
2596
|
exports.cleanPath = cleanPath;
|
|
@@ -2634,6 +2626,7 @@
|
|
|
2634
2626
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2635
2627
|
exports.resolvePath = resolvePath;
|
|
2636
2628
|
exports.rootRouteId = rootRouteId;
|
|
2629
|
+
exports.rootRouteWithContext = rootRouteWithContext;
|
|
2637
2630
|
exports.routerContext = routerContext;
|
|
2638
2631
|
exports.shallow = shallow;
|
|
2639
2632
|
exports.stringifySearchWith = stringifySearchWith;
|
|
@@ -2648,7 +2641,7 @@
|
|
|
2648
2641
|
exports.useMatches = useMatches;
|
|
2649
2642
|
exports.useNavigate = useNavigate;
|
|
2650
2643
|
exports.useParams = useParams;
|
|
2651
|
-
exports.
|
|
2644
|
+
exports.useRouteContext = useRouteContext;
|
|
2652
2645
|
exports.useRouter = useRouter;
|
|
2653
2646
|
exports.useRouterState = useRouterState;
|
|
2654
2647
|
exports.useSearch = useSearch;
|