@tanstack/react-router 0.0.1-beta.275 → 0.0.1-beta.277
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 +9 -0
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +12 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +21 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +353 -353
- package/build/types/Matches.d.ts +3 -0
- package/build/types/RouterProvider.d.ts +2 -2
- package/build/types/route.d.ts +13 -7
- package/build/types/router.d.ts +2 -1
- package/build/umd/index.development.js +21 -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 +24 -0
- package/src/RouterProvider.tsx +1 -1
- package/src/route.ts +20 -7
- package/src/router.ts +4 -3
package/build/types/Matches.d.ts
CHANGED
|
@@ -55,6 +55,9 @@ export declare function useMatches<T = RouteMatch[]>(opts?: {
|
|
|
55
55
|
export declare function useParentMatches<T = RouteMatch[]>(opts?: {
|
|
56
56
|
select?: (matches: RouteMatch[]) => T;
|
|
57
57
|
}): T;
|
|
58
|
+
export declare function useLoaderDeps<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>['loaderDeps']>(opts: StrictOrFrom<TFrom> & {
|
|
59
|
+
select?: (match: TRouteMatch) => TSelected;
|
|
60
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
58
61
|
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> & {
|
|
59
62
|
select?: (match: TRouteMatch) => TSelected;
|
|
60
63
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
@@ -3,7 +3,7 @@ import { NavigateOptions, ResolveRelativePath, ToOptions } from './link';
|
|
|
3
3
|
import { ParsedLocation } from './location';
|
|
4
4
|
import { AnyRoute } from './route';
|
|
5
5
|
import { RouteById, RoutePaths } from './routeInfo';
|
|
6
|
-
import {
|
|
6
|
+
import { RegisteredRouter, Router, RouterOptions, RouterState } from './router';
|
|
7
7
|
import { NoInfer } from './utils';
|
|
8
8
|
import { MatchRouteOptions } from './Matches';
|
|
9
9
|
import { RouteMatch } from './Matches';
|
|
@@ -20,7 +20,7 @@ export interface MatchLocation {
|
|
|
20
20
|
}
|
|
21
21
|
export type NavigateFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
|
|
22
22
|
export type MatchRouteFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
23
|
-
export type BuildLocationFn<TRouteTree extends AnyRoute> = (opts:
|
|
23
|
+
export type BuildLocationFn<TRouteTree extends AnyRoute> = (opts: ToOptions<TRouteTree>) => ParsedLocation;
|
|
24
24
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string);
|
|
25
25
|
export declare let routerContext: React.Context<Router<any, Record<string, any>>>;
|
|
26
26
|
export declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): React.JSX.Element;
|
package/build/types/route.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute ex
|
|
|
59
59
|
context: TParentRoute['types']['allContext'];
|
|
60
60
|
location: ParsedLocation;
|
|
61
61
|
navigate: NavigateFn<AnyRoute>;
|
|
62
|
-
buildLocation: BuildLocationFn<
|
|
62
|
+
buildLocation: BuildLocationFn<TParentRoute>;
|
|
63
63
|
cause: 'preload' | 'enter' | 'stay';
|
|
64
64
|
}) => Promise<TRouteContext> | TRouteContext | void;
|
|
65
65
|
export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>> = MetaOptions & {
|
|
@@ -134,25 +134,28 @@ export type RouteConstraints = {
|
|
|
134
134
|
TChildren: unknown;
|
|
135
135
|
TRouteTree: AnyRoute;
|
|
136
136
|
};
|
|
137
|
-
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']> {
|
|
137
|
+
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'], TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'], TLoaderData extends any = TRoute['types']['loaderData']> {
|
|
138
138
|
id: TId;
|
|
139
139
|
constructor({ id }: {
|
|
140
140
|
id: TId;
|
|
141
141
|
});
|
|
142
142
|
useMatch: <TSelected = TAllContext>(opts?: {
|
|
143
|
-
select?: ((
|
|
143
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
144
144
|
} | undefined) => TSelected;
|
|
145
145
|
useRouteContext: <TSelected = TAllContext>(opts?: {
|
|
146
|
-
select?: ((
|
|
146
|
+
select?: ((s: TAllContext) => TSelected) | undefined;
|
|
147
147
|
} | undefined) => TSelected;
|
|
148
148
|
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
149
|
-
select?: ((
|
|
149
|
+
select?: ((s: TFullSearchSchema) => TSelected) | undefined;
|
|
150
150
|
} | undefined) => TSelected;
|
|
151
151
|
useParams: <TSelected = TAllParams>(opts?: {
|
|
152
|
-
select?: ((
|
|
152
|
+
select?: ((s: TAllParams) => TSelected) | undefined;
|
|
153
|
+
} | undefined) => TSelected;
|
|
154
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
155
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
153
156
|
} | undefined) => TSelected;
|
|
154
157
|
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
155
|
-
select?: ((
|
|
158
|
+
select?: ((s: TLoaderData) => TSelected) | undefined;
|
|
156
159
|
} | undefined) => TSelected;
|
|
157
160
|
}
|
|
158
161
|
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, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
@@ -205,6 +208,9 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
205
208
|
useParams: <TSelected = TAllParams>(opts?: {
|
|
206
209
|
select?: ((search: TAllParams) => TSelected) | undefined;
|
|
207
210
|
} | undefined) => TSelected;
|
|
211
|
+
useLoaderDeps: <TSelected = TLoaderDeps>(opts?: {
|
|
212
|
+
select?: ((s: TLoaderDeps) => TSelected) | undefined;
|
|
213
|
+
} | undefined) => TSelected;
|
|
208
214
|
useLoaderData: <TSelected = TLoaderData>(opts?: {
|
|
209
215
|
select?: ((search: TLoaderData) => TSelected) | undefined;
|
|
210
216
|
} | undefined) => TSelected;
|
package/build/types/router.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { AnyRouteMatch, RouteMatch } from './Matches';
|
|
|
9
9
|
import { ParsedLocation } from './location';
|
|
10
10
|
import { SearchSerializer, SearchParser } from './searchParams';
|
|
11
11
|
import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, MatchRouteFn, NavigateFn } from './RouterProvider';
|
|
12
|
+
import { ToOptions } from './link';
|
|
12
13
|
declare global {
|
|
13
14
|
interface Window {
|
|
14
15
|
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
@@ -169,7 +170,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
169
170
|
load: (opts?: {
|
|
170
171
|
invalidate?: boolean;
|
|
171
172
|
}) => Promise<void>;
|
|
172
|
-
preloadRoute: (navigateOpts?:
|
|
173
|
+
preloadRoute: (navigateOpts?: ToOptions<TRouteTree>) => Promise<RouteMatch<AnyRoute, any>[]>;
|
|
173
174
|
matchRoute: MatchRouteFn<TRouteTree>;
|
|
174
175
|
injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
|
|
175
176
|
dehydrateData: <T>(key: any, getData: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
@@ -1071,6 +1071,14 @@
|
|
|
1071
1071
|
}
|
|
1072
1072
|
});
|
|
1073
1073
|
}
|
|
1074
|
+
function useLoaderDeps(opts) {
|
|
1075
|
+
return useMatch({
|
|
1076
|
+
...opts,
|
|
1077
|
+
select: s => {
|
|
1078
|
+
return typeof opts.select === 'function' ? opts.select(s?.loaderDeps) : s?.loaderDeps;
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1074
1082
|
function useLoaderData(opts) {
|
|
1075
1083
|
return useMatch({
|
|
1076
1084
|
...opts,
|
|
@@ -1497,6 +1505,12 @@
|
|
|
1497
1505
|
from: this.id
|
|
1498
1506
|
});
|
|
1499
1507
|
};
|
|
1508
|
+
useLoaderDeps = opts => {
|
|
1509
|
+
return useLoaderDeps({
|
|
1510
|
+
...opts,
|
|
1511
|
+
from: this.id
|
|
1512
|
+
});
|
|
1513
|
+
};
|
|
1500
1514
|
useLoaderData = opts => {
|
|
1501
1515
|
return useLoaderData({
|
|
1502
1516
|
...opts,
|
|
@@ -1583,6 +1597,12 @@
|
|
|
1583
1597
|
from: this.id
|
|
1584
1598
|
});
|
|
1585
1599
|
};
|
|
1600
|
+
useLoaderDeps = opts => {
|
|
1601
|
+
return useLoaderDeps({
|
|
1602
|
+
...opts,
|
|
1603
|
+
from: this.id
|
|
1604
|
+
});
|
|
1605
|
+
};
|
|
1586
1606
|
useLoaderData = opts => {
|
|
1587
1607
|
return useLoaderData({
|
|
1588
1608
|
...opts,
|
|
@@ -3328,6 +3348,7 @@
|
|
|
3328
3348
|
exports.useLayoutEffect = useLayoutEffect$1;
|
|
3329
3349
|
exports.useLinkProps = useLinkProps;
|
|
3330
3350
|
exports.useLoaderData = useLoaderData;
|
|
3351
|
+
exports.useLoaderDeps = useLoaderDeps;
|
|
3331
3352
|
exports.useMatch = useMatch;
|
|
3332
3353
|
exports.useMatchRoute = useMatchRoute;
|
|
3333
3354
|
exports.useMatches = useMatches;
|