@tanstack/react-router 0.0.1-beta.207 → 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 +25 -15
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/index.js +3 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/react.js +11 -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 +41 -35
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +171 -171
- package/build/types/RouteMatch.d.ts +1 -1
- package/build/types/fileRoute.d.ts +17 -2
- package/build/types/react.d.ts +5 -4
- package/build/types/route.d.ts +46 -39
- package/build/types/router.d.ts +5 -5
- package/build/umd/index.development.js +43 -36
- 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 +19 -15
- package/src/fileRoute.ts +10 -8
- package/src/react.tsx +27 -11
- package/src/route.ts +112 -106
- 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;
|
|
@@ -98,6 +98,7 @@ export declare function useParams<TRouteTree extends AnyRoute = RegisteredRouter
|
|
|
98
98
|
export declare function useNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(defaultOpts?: {
|
|
99
99
|
from?: TDefaultFrom;
|
|
100
100
|
}): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">(opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> | undefined) => Promise<void>;
|
|
101
|
+
export declare function typedNavigate<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDefaultFrom extends RoutePaths<TRouteTree> = '/'>(navigate: (opts: NavigateOptions<any>) => Promise<void>): <TFrom extends RoutePaths<TRouteTree> = TDefaultFrom, TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "">(opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> | undefined) => Promise<void>;
|
|
101
102
|
export declare function useMatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "", TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>>(opts: MakeUseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
102
103
|
export declare function Matches(): JSX.Element;
|
|
103
104
|
export declare function MatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): any;
|
package/build/types/route.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { RoutePaths } from './routeInfo';
|
|
|
2
2
|
import { AnyRouter } from './router';
|
|
3
3
|
import { AnyRouteMatch } from './RouteMatch';
|
|
4
4
|
import { Expand, IsAny, NoInfer, PickRequired, UnionToIntersection, Assign } from './utils';
|
|
5
|
-
import { ParsePathParams, ToSubOptions } from './link';
|
|
5
|
+
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
|
|
6
6
|
import { ErrorRouteComponent, PendingRouteComponent, RouteComponent } from './react';
|
|
7
7
|
import { ParsedLocation } from './location';
|
|
8
8
|
export declare const rootRouteId: "__root__";
|
|
@@ -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,15 +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
|
-
|
|
50
|
-
|
|
56
|
+
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
57
|
+
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
58
|
+
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TAllContext extends AnyContext> = MetaOptions & {
|
|
51
59
|
caseSensitive?: boolean;
|
|
52
60
|
wrapInSuspense?: boolean;
|
|
53
61
|
component?: RouteComponent<TFullSearchSchema, TAllParams, TAllContext>;
|
|
@@ -75,15 +83,17 @@ export type DefinedPathParamWarning = 'Path params cannot be redefined by child
|
|
|
75
83
|
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
76
84
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
77
85
|
};
|
|
78
|
-
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> & {
|
|
79
87
|
parentMatchPromise?: Promise<void>;
|
|
80
88
|
}) => any;
|
|
81
|
-
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> {
|
|
82
90
|
abortController: AbortController;
|
|
83
91
|
preload: boolean;
|
|
84
92
|
params: TAllParams;
|
|
85
93
|
search: TFullSearchSchema;
|
|
86
|
-
|
|
94
|
+
context: Expand<Assign<TAllContext, TRouteContext>>;
|
|
95
|
+
location: ParsedLocation<TFullSearchSchema>;
|
|
96
|
+
navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>;
|
|
87
97
|
}
|
|
88
98
|
export type SearchFilter<T, U = T> = (prev: T) => U;
|
|
89
99
|
export type ResolveId<TParentRoute, TCustomId extends string, TPath extends string> = TParentRoute extends {
|
|
@@ -116,16 +126,16 @@ export type RouteConstraints = {
|
|
|
116
126
|
TParams: Record<string, any>;
|
|
117
127
|
TAllParams: Record<string, any>;
|
|
118
128
|
TParentContext: AnyContext;
|
|
119
|
-
|
|
129
|
+
TRouteContext: RouteContext;
|
|
120
130
|
TAllContext: AnyContext;
|
|
121
|
-
|
|
131
|
+
TRouterContext: AnyContext;
|
|
122
132
|
TChildren: unknown;
|
|
123
133
|
TRouteTree: AnyRoute;
|
|
124
134
|
};
|
|
125
|
-
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> {
|
|
126
136
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
127
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
128
|
-
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>>;
|
|
129
139
|
parentRoute: TParentRoute;
|
|
130
140
|
id: TId;
|
|
131
141
|
path: TPath;
|
|
@@ -135,7 +145,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
135
145
|
originalIndex?: number;
|
|
136
146
|
router?: AnyRouter;
|
|
137
147
|
rank: number;
|
|
138
|
-
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
148
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>);
|
|
139
149
|
types: {
|
|
140
150
|
parentRoute: TParentRoute;
|
|
141
151
|
path: TPath;
|
|
@@ -147,23 +157,23 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
147
157
|
fullSearchSchema: TFullSearchSchema;
|
|
148
158
|
params: TParams;
|
|
149
159
|
allParams: TAllParams;
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
routeContext: TRouteContext;
|
|
161
|
+
allContext: TAllContext;
|
|
152
162
|
children: TChildren;
|
|
153
163
|
routeTree: TRouteTree;
|
|
154
|
-
|
|
164
|
+
routerContext: TRouterContext;
|
|
155
165
|
};
|
|
156
166
|
init: (opts: {
|
|
157
167
|
originalIndex: number;
|
|
158
168
|
}) => void;
|
|
159
|
-
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams,
|
|
160
|
-
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;
|
|
161
171
|
static __onInit: (route: any) => void;
|
|
162
|
-
useMatch: <TSelected =
|
|
163
|
-
select?: ((search:
|
|
172
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
173
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
164
174
|
} | undefined) => TSelected;
|
|
165
|
-
|
|
166
|
-
select?: ((search:
|
|
175
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
176
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
167
177
|
} | undefined) => TSelected;
|
|
168
178
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
169
179
|
select?: ((search: TFullSearchSchema) => TSelected) | undefined;
|
|
@@ -173,11 +183,8 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
173
183
|
} | undefined) => TSelected;
|
|
174
184
|
}
|
|
175
185
|
export type AnyRootRoute = RootRoute<any, any, any>;
|
|
176
|
-
export declare
|
|
177
|
-
|
|
178
|
-
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>;
|
|
179
|
-
}
|
|
180
|
-
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
|
|
181
188
|
'/', // TPath
|
|
182
189
|
'/', // TFullPath
|
|
183
190
|
string, // TCustomId
|
|
@@ -186,9 +193,9 @@ TSearchSchema, // TSearchSchema
|
|
|
186
193
|
TSearchSchema, // TFullSearchSchema
|
|
187
194
|
{}, // TParams
|
|
188
195
|
{}, // TAllParams
|
|
189
|
-
|
|
190
|
-
Expand<Assign<
|
|
191
|
-
|
|
196
|
+
TRouteContext, // TRouteContext
|
|
197
|
+
Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
|
|
198
|
+
TRouterContext, // TRouterContext
|
|
192
199
|
any, // TChildren
|
|
193
200
|
any> {
|
|
194
201
|
constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
|
|
@@ -198,8 +205,8 @@ any> {
|
|
|
198
205
|
TSearchSchema, // TFullSearchSchema
|
|
199
206
|
{}, // TParams
|
|
200
207
|
{}, // TAllParams
|
|
201
|
-
|
|
202
|
-
Assign<
|
|
208
|
+
TRouteContext, // TRouteContext
|
|
209
|
+
Assign<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
203
210
|
}
|
|
204
211
|
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
205
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,22 +1491,27 @@
|
|
|
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
|
-
|
|
1501
|
-
location: state.location
|
|
1500
|
+
context: parentContext,
|
|
1501
|
+
location: state.location,
|
|
1502
|
+
// TODO: This might need to be latestLocationRef.current...?
|
|
1503
|
+
navigate: opts => navigate({
|
|
1504
|
+
...opts,
|
|
1505
|
+
from: match.pathname
|
|
1506
|
+
})
|
|
1502
1507
|
})) ?? {};
|
|
1503
|
-
const
|
|
1504
|
-
...
|
|
1505
|
-
...
|
|
1508
|
+
const context = {
|
|
1509
|
+
...parentContext,
|
|
1510
|
+
...beforeLoadContext
|
|
1506
1511
|
};
|
|
1507
1512
|
matches[index] = match = {
|
|
1508
1513
|
...match,
|
|
1509
|
-
|
|
1514
|
+
context: replaceEqualDeep(match.context, context)
|
|
1510
1515
|
};
|
|
1511
1516
|
} catch (err) {
|
|
1512
1517
|
handleError(err, 'BEFORE_LOAD');
|
|
@@ -1552,7 +1557,12 @@
|
|
|
1552
1557
|
preload: !!preload,
|
|
1553
1558
|
parentMatchPromise,
|
|
1554
1559
|
abortController: match.abortController,
|
|
1555
|
-
|
|
1560
|
+
context: match.context,
|
|
1561
|
+
location: state.location,
|
|
1562
|
+
navigate: opts => navigate({
|
|
1563
|
+
...opts,
|
|
1564
|
+
from: match.pathname
|
|
1565
|
+
})
|
|
1556
1566
|
});
|
|
1557
1567
|
await Promise.all([componentsPromise, loaderPromise]);
|
|
1558
1568
|
if (latestPromise = checkLatest()) return await latestPromise;
|
|
@@ -2102,10 +2112,10 @@
|
|
|
2102
2112
|
});
|
|
2103
2113
|
return matchSelection;
|
|
2104
2114
|
}
|
|
2105
|
-
function
|
|
2115
|
+
function useRouteContext(opts) {
|
|
2106
2116
|
return useMatch({
|
|
2107
2117
|
...opts,
|
|
2108
|
-
select: match => opts?.select ? opts.select(match.
|
|
2118
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
2109
2119
|
});
|
|
2110
2120
|
}
|
|
2111
2121
|
function useSearch(opts) {
|
|
@@ -2139,6 +2149,9 @@
|
|
|
2139
2149
|
});
|
|
2140
2150
|
}, []);
|
|
2141
2151
|
}
|
|
2152
|
+
function typedNavigate(navigate) {
|
|
2153
|
+
return navigate;
|
|
2154
|
+
}
|
|
2142
2155
|
function useMatchRoute() {
|
|
2143
2156
|
const {
|
|
2144
2157
|
state,
|
|
@@ -2179,7 +2192,7 @@
|
|
|
2179
2192
|
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
2180
2193
|
...props,
|
|
2181
2194
|
useMatch: route.useMatch,
|
|
2182
|
-
|
|
2195
|
+
useRouteContext: route.useRouteContext,
|
|
2183
2196
|
useSearch: route.useSearch,
|
|
2184
2197
|
useParams: route.useParams
|
|
2185
2198
|
});
|
|
@@ -2235,7 +2248,7 @@
|
|
|
2235
2248
|
return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
|
|
2236
2249
|
...props,
|
|
2237
2250
|
useMatch: route.useMatch,
|
|
2238
|
-
|
|
2251
|
+
useRouteContext: route.useRouteContext,
|
|
2239
2252
|
useSearch: route.useSearch,
|
|
2240
2253
|
useParams: route.useParams
|
|
2241
2254
|
});
|
|
@@ -2245,7 +2258,7 @@
|
|
|
2245
2258
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
2246
2259
|
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
2247
2260
|
useMatch: route.useMatch,
|
|
2248
|
-
|
|
2261
|
+
useRouteContext: route.useRouteContext,
|
|
2249
2262
|
useSearch: route.useSearch,
|
|
2250
2263
|
useParams: route.useParams
|
|
2251
2264
|
})
|
|
@@ -2278,7 +2291,7 @@
|
|
|
2278
2291
|
if (comp) {
|
|
2279
2292
|
return /*#__PURE__*/React__namespace.createElement(comp, {
|
|
2280
2293
|
useMatch: route.useMatch,
|
|
2281
|
-
|
|
2294
|
+
useRouteContext: route.useRouteContext,
|
|
2282
2295
|
useSearch: route.useSearch,
|
|
2283
2296
|
useParams: route.useParams
|
|
2284
2297
|
});
|
|
@@ -2454,14 +2467,8 @@
|
|
|
2454
2467
|
|
|
2455
2468
|
const rootRouteId = '__root__';
|
|
2456
2469
|
|
|
2457
|
-
// export type MetaOptions = keyof PickRequired<RouteMeta> extends never
|
|
2458
|
-
// ? {
|
|
2459
|
-
// meta?: RouteMeta
|
|
2460
|
-
// }
|
|
2461
|
-
// : {
|
|
2462
|
-
// meta: RouteMeta
|
|
2463
|
-
// }
|
|
2464
2470
|
// The parse type here allows a zod schema to be passed directly to the validator
|
|
2471
|
+
|
|
2465
2472
|
class Route {
|
|
2466
2473
|
// Set up in this.init()
|
|
2467
2474
|
|
|
@@ -2525,11 +2532,11 @@
|
|
|
2525
2532
|
from: this.id
|
|
2526
2533
|
});
|
|
2527
2534
|
};
|
|
2528
|
-
|
|
2535
|
+
useRouteContext = opts => {
|
|
2529
2536
|
return useMatch({
|
|
2530
2537
|
...opts,
|
|
2531
2538
|
from: this.id,
|
|
2532
|
-
select: d => opts?.select ? opts.select(d.
|
|
2539
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
2533
2540
|
});
|
|
2534
2541
|
};
|
|
2535
2542
|
useSearch = opts => {
|
|
@@ -2545,9 +2552,8 @@
|
|
|
2545
2552
|
});
|
|
2546
2553
|
};
|
|
2547
2554
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
createRootRoute = options => {
|
|
2555
|
+
function rootRouteWithContext() {
|
|
2556
|
+
return options => {
|
|
2551
2557
|
return new RootRoute(options);
|
|
2552
2558
|
};
|
|
2553
2559
|
}
|
|
@@ -2585,7 +2591,6 @@
|
|
|
2585
2591
|
exports.RootRoute = RootRoute;
|
|
2586
2592
|
exports.Route = Route;
|
|
2587
2593
|
exports.Router = Router;
|
|
2588
|
-
exports.RouterMeta = RouterMeta;
|
|
2589
2594
|
exports.RouterProvider = RouterProvider;
|
|
2590
2595
|
exports.SearchParamError = SearchParamError;
|
|
2591
2596
|
exports.cleanPath = cleanPath;
|
|
@@ -2621,12 +2626,14 @@
|
|
|
2621
2626
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2622
2627
|
exports.resolvePath = resolvePath;
|
|
2623
2628
|
exports.rootRouteId = rootRouteId;
|
|
2629
|
+
exports.rootRouteWithContext = rootRouteWithContext;
|
|
2624
2630
|
exports.routerContext = routerContext;
|
|
2625
2631
|
exports.shallow = shallow;
|
|
2626
2632
|
exports.stringifySearchWith = stringifySearchWith;
|
|
2627
2633
|
exports.trimPath = trimPath;
|
|
2628
2634
|
exports.trimPathLeft = trimPathLeft;
|
|
2629
2635
|
exports.trimPathRight = trimPathRight;
|
|
2636
|
+
exports.typedNavigate = typedNavigate;
|
|
2630
2637
|
exports.useBlocker = useBlocker;
|
|
2631
2638
|
exports.useLinkProps = useLinkProps;
|
|
2632
2639
|
exports.useMatch = useMatch;
|
|
@@ -2634,7 +2641,7 @@
|
|
|
2634
2641
|
exports.useMatches = useMatches;
|
|
2635
2642
|
exports.useNavigate = useNavigate;
|
|
2636
2643
|
exports.useParams = useParams;
|
|
2637
|
-
exports.
|
|
2644
|
+
exports.useRouteContext = useRouteContext;
|
|
2638
2645
|
exports.useRouter = useRouter;
|
|
2639
2646
|
exports.useRouterState = useRouterState;
|
|
2640
2647
|
exports.useSearch = useSearch;
|