@tanstack/react-router 0.0.1-beta.263 → 0.0.1-beta.265
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +39 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +2 -0
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +41 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/Matches.d.ts +2 -1
- package/build/types/route.d.ts +23 -2
- package/build/umd/index.development.js +41 -0
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +2 -1
- package/src/route.ts +58 -2
- package/src/router.ts +5 -2
package/build/types/Matches.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId ext
|
|
|
21
21
|
loadPromise?: Promise<void>;
|
|
22
22
|
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData'];
|
|
23
23
|
__resolveLoadPromise?: () => void;
|
|
24
|
+
routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext'];
|
|
24
25
|
context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
|
|
25
26
|
search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
|
|
26
27
|
fetchedAt: number;
|
|
@@ -52,6 +53,6 @@ export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter[
|
|
|
52
53
|
export declare function useMatches<T = RouteMatch[]>(opts?: {
|
|
53
54
|
select?: (matches: RouteMatch[]) => T;
|
|
54
55
|
}): T;
|
|
55
|
-
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = TRouteMatch['loaderData']>(opts: StrictOrFrom<TFrom> & {
|
|
56
|
+
export declare function useLoaderData<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch extends RouteMatch<TRouteTree, TFrom> = RouteMatch<TRouteTree, TFrom>, TSelected = Required<TRouteMatch>['loaderData']>(opts: StrictOrFrom<TFrom> & {
|
|
56
57
|
select?: (match: TRouteMatch) => TSelected;
|
|
57
58
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
package/build/types/route.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { AnyRouteMatch } from './Matches';
|
|
3
3
|
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link';
|
|
4
4
|
import { ParsedLocation } from './location';
|
|
5
|
-
import { RoutePaths } from './routeInfo';
|
|
6
|
-
import { AnyRouter } from './router';
|
|
5
|
+
import { RouteById, RouteIds, RoutePaths } from './routeInfo';
|
|
6
|
+
import { AnyRouter, RegisteredRouter } from './router';
|
|
7
7
|
import { Assign, Expand, IsAny, NoInfer, PickRequired, UnionToIntersection } from './utils';
|
|
8
8
|
import { BuildLocationFn, NavigateFn } from './RouterProvider';
|
|
9
9
|
export declare const rootRouteId: "__root__";
|
|
@@ -141,6 +141,27 @@ export type RouteConstraints = {
|
|
|
141
141
|
TChildren: unknown;
|
|
142
142
|
TRouteTree: AnyRoute;
|
|
143
143
|
};
|
|
144
|
+
export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>, TFullSearchSchema extends Record<string, any> = TRoute['types']['fullSearchSchema'], TAllParams extends AnyPathParams = TRoute['types']['allParams'], TAllContext extends Record<string, any> = TRoute['types']['allContext'], TLoaderData extends any = TRoute['types']['loaderData']> {
|
|
145
|
+
id: TId;
|
|
146
|
+
constructor({ id }: {
|
|
147
|
+
id: TId;
|
|
148
|
+
});
|
|
149
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
150
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
151
|
+
} | undefined) => TSelected;
|
|
152
|
+
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
153
|
+
select?: ((search: TAllContext) => TSelected) | undefined;
|
|
154
|
+
} | undefined) => TSelected;
|
|
155
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
156
|
+
select?: ((search: TFullSearchSchema) => TSelected) | undefined;
|
|
157
|
+
} | undefined) => TSelected;
|
|
158
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
159
|
+
select?: ((search: TAllParams) => TSelected) | undefined;
|
|
160
|
+
} | undefined) => TSelected;
|
|
161
|
+
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
162
|
+
select?: ((search: TLoaderData) => TSelected) | undefined;
|
|
163
|
+
} | undefined) => TSelected;
|
|
164
|
+
}
|
|
144
165
|
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, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
145
166
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
146
167
|
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData>;
|
|
@@ -1122,6 +1122,44 @@
|
|
|
1122
1122
|
|
|
1123
1123
|
// The parse type here allows a zod schema to be passed directly to the validator
|
|
1124
1124
|
|
|
1125
|
+
class RouteApi {
|
|
1126
|
+
constructor({
|
|
1127
|
+
id
|
|
1128
|
+
}) {
|
|
1129
|
+
this.id = id;
|
|
1130
|
+
}
|
|
1131
|
+
useMatch = opts => {
|
|
1132
|
+
return useMatch({
|
|
1133
|
+
...opts,
|
|
1134
|
+
from: this.id
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
useRouteContext = opts => {
|
|
1138
|
+
return useMatch({
|
|
1139
|
+
...opts,
|
|
1140
|
+
from: this.id,
|
|
1141
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
1142
|
+
});
|
|
1143
|
+
};
|
|
1144
|
+
useSearch = opts => {
|
|
1145
|
+
return useSearch({
|
|
1146
|
+
...opts,
|
|
1147
|
+
from: this.id
|
|
1148
|
+
});
|
|
1149
|
+
};
|
|
1150
|
+
useParams = opts => {
|
|
1151
|
+
return useParams({
|
|
1152
|
+
...opts,
|
|
1153
|
+
from: this.id
|
|
1154
|
+
});
|
|
1155
|
+
};
|
|
1156
|
+
useLoaderData = opts => {
|
|
1157
|
+
return useLoaderData({
|
|
1158
|
+
...opts,
|
|
1159
|
+
from: this.id
|
|
1160
|
+
});
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1125
1163
|
class Route {
|
|
1126
1164
|
// Set up in this.init()
|
|
1127
1165
|
|
|
@@ -2280,6 +2318,7 @@
|
|
|
2280
2318
|
error: undefined,
|
|
2281
2319
|
paramsError: parseErrors[index],
|
|
2282
2320
|
loadPromise: Promise.resolve(),
|
|
2321
|
+
routeContext: undefined,
|
|
2283
2322
|
context: undefined,
|
|
2284
2323
|
abortController: new AbortController(),
|
|
2285
2324
|
shouldReloadDeps: undefined,
|
|
@@ -2559,6 +2598,7 @@
|
|
|
2559
2598
|
};
|
|
2560
2599
|
matches[index] = match = {
|
|
2561
2600
|
...match,
|
|
2601
|
+
routeContext: replaceEqualDeep(match.routeContext, beforeLoadContext),
|
|
2562
2602
|
context: replaceEqualDeep(match.context, context),
|
|
2563
2603
|
abortController
|
|
2564
2604
|
};
|
|
@@ -3186,6 +3226,7 @@
|
|
|
3186
3226
|
exports.PathParamError = PathParamError;
|
|
3187
3227
|
exports.RootRoute = RootRoute;
|
|
3188
3228
|
exports.Route = Route;
|
|
3229
|
+
exports.RouteApi = RouteApi;
|
|
3189
3230
|
exports.Router = Router;
|
|
3190
3231
|
exports.RouterProvider = RouterProvider;
|
|
3191
3232
|
exports.ScrollRestoration = ScrollRestoration;
|