@tanstack/react-router 0.0.1-beta.174 → 0.0.1-beta.176
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/react.js.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +114 -114
- package/build/types/awaited.d.ts +8 -0
- package/build/types/index.d.ts +3 -197
- package/build/types/react.d.ts +173 -0
- package/build/types/scroll-restoration.d.ts +3 -0
- package/build/umd/index.development.js +55 -34
- 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 +3 -3
- package/src/react.tsx +1 -1
package/build/types/index.d.ts
CHANGED
|
@@ -1,199 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @tanstack/react-router/src/index.tsx
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
import { NoInfer } from '@tanstack/react-store';
|
|
12
1
|
export { useStore } from '@tanstack/react-store';
|
|
13
|
-
import * as _tanstack_router_core from '@tanstack/router-core';
|
|
14
|
-
import { AnySearchSchema, AnyPathParams, AnyContext, RouteConstraints, AnyRoute, ResolveFullPath, ResolveId, ResolveFullSearchSchema, ParsePathParams, MergeParamsFromParent, RouteContext, UseLoaderResult, AnyRouteProps, RoutePaths, RegisteredRouter, LinkOptions, ToOptions, MatchRouteOptions, RouteByPath, ResolveRelativePath, NavigateOptions, RouterOptions, Router, RouteMatch, RouteIds, RouteById, ParseRoute, RoutesById, AllParams, ScrollRestorationOptions, DeferredPromise } from '@tanstack/router-core';
|
|
15
2
|
export * from '@tanstack/router-core';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
20
|
-
RouteComponent: RouteComponent<RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
21
|
-
}
|
|
22
|
-
interface RegisterErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
23
|
-
ErrorRouteComponent: RouteComponent<ErrorRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
24
|
-
}
|
|
25
|
-
interface RegisterPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
26
|
-
PendingRouteComponent: RouteComponent<PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
27
|
-
}
|
|
28
|
-
interface Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Record<ParsePathParams<TPath>, string>, TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<TParentRoute['types']['allParams'], TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
29
|
-
useMatch: <TSelected = TAllContext>(opts?: {
|
|
30
|
-
select?: (search: TAllContext) => TSelected;
|
|
31
|
-
}) => TSelected;
|
|
32
|
-
useLoader: <TSelected = TLoader>(opts?: {
|
|
33
|
-
select?: (search: TLoader) => TSelected;
|
|
34
|
-
}) => UseLoaderResult<TSelected>;
|
|
35
|
-
useContext: <TSelected = TAllContext>(opts?: {
|
|
36
|
-
select?: (search: TAllContext) => TSelected;
|
|
37
|
-
}) => TSelected;
|
|
38
|
-
useRouteContext: <TSelected = TRouteContext>(opts?: {
|
|
39
|
-
select?: (search: TRouteContext) => TSelected;
|
|
40
|
-
}) => TSelected;
|
|
41
|
-
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
42
|
-
select?: (search: TFullSearchSchema) => TSelected;
|
|
43
|
-
}) => TSelected;
|
|
44
|
-
useParams: <TSelected = TAllParams>(opts?: {
|
|
45
|
-
select?: (search: TAllParams) => TSelected;
|
|
46
|
-
}) => TSelected;
|
|
47
|
-
}
|
|
48
|
-
interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
49
|
-
RouteProps: RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
50
|
-
}
|
|
51
|
-
interface RegisterPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
52
|
-
PendingRouteProps: PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
53
|
-
}
|
|
54
|
-
interface RegisterErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
55
|
-
ErrorRouteProps: ErrorRouteProps;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
type RouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = {
|
|
59
|
-
useLoader: <TStrict extends boolean = true, TSelected = TLoader>(opts?: {
|
|
60
|
-
strict?: TStrict;
|
|
61
|
-
select?: (search: TLoader) => TSelected;
|
|
62
|
-
}) => TStrict extends true ? UseLoaderResult<TSelected> : UseLoaderResult<TSelected> | undefined;
|
|
63
|
-
useMatch: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
|
|
64
|
-
strict?: TStrict;
|
|
65
|
-
select?: (search: TAllContext) => TSelected;
|
|
66
|
-
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
67
|
-
useContext: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
|
|
68
|
-
strict?: TStrict;
|
|
69
|
-
select?: (search: TAllContext) => TSelected;
|
|
70
|
-
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
71
|
-
useRouteContext: <TStrict extends boolean = true, TSelected = TRouteContext>(opts?: {
|
|
72
|
-
strict?: TStrict;
|
|
73
|
-
select?: (search: TRouteContext) => TSelected;
|
|
74
|
-
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
75
|
-
useSearch: <TStrict extends boolean = true, TSelected = TFullSearchSchema>(opts?: {
|
|
76
|
-
strict?: TStrict;
|
|
77
|
-
select?: (search: TFullSearchSchema) => TSelected;
|
|
78
|
-
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
79
|
-
useParams: <TStrict extends boolean = true, TSelected = TAllParams>(opts?: {
|
|
80
|
-
strict?: TStrict;
|
|
81
|
-
select?: (search: TAllParams) => TSelected;
|
|
82
|
-
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
83
|
-
};
|
|
84
|
-
type ErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = {
|
|
85
|
-
error: unknown;
|
|
86
|
-
info: {
|
|
87
|
-
componentStack: string;
|
|
88
|
-
};
|
|
89
|
-
} & Omit<RouteProps<unknown, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>, 'useLoader'>;
|
|
90
|
-
type PendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = Omit<RouteProps<unknown, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>, 'useLoader'>;
|
|
91
|
-
type ReactNode = any;
|
|
92
|
-
type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.LazyExoticComponent<(props: TProps) => ReactNode>;
|
|
93
|
-
type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
94
|
-
preload?: () => Promise<void>;
|
|
95
|
-
};
|
|
96
|
-
type ErrorRouteComponent = AsyncRouteComponent<ErrorRouteComponentProps>;
|
|
97
|
-
type ErrorRouteComponentProps = {
|
|
98
|
-
error: Error;
|
|
99
|
-
info: {
|
|
100
|
-
componentStack: string;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
type AnyRouteComponent = RouteComponent<AnyRouteProps>;
|
|
104
|
-
type RouteComponent<TProps> = AsyncRouteComponent<TProps>;
|
|
105
|
-
declare function lazyRouteComponent<T extends Record<string, any>, TKey extends keyof T = 'default'>(importer: () => Promise<T>, exportName?: TKey): T[TKey] extends (props: infer TProps) => any ? AsyncRouteComponent<TProps> : never;
|
|
106
|
-
type LinkPropsOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = LinkOptions<RegisteredRouter['routeTree'], TFrom, TTo> & {
|
|
107
|
-
activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
108
|
-
inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
109
|
-
startTransition?: boolean;
|
|
110
|
-
};
|
|
111
|
-
type MakeUseMatchRouteOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions;
|
|
112
|
-
type MakeMatchRouteOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions & {
|
|
113
|
-
children?: ((params?: RouteByPath<RegisteredRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
|
114
|
-
};
|
|
115
|
-
type MakeLinkPropsOptions<TFrom extends string = '/', TTo extends string = ''> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
116
|
-
type MakeLinkOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = LinkPropsOptions<TFrom, TTo> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
117
|
-
children?: React.ReactNode | ((state: {
|
|
118
|
-
isActive: boolean;
|
|
119
|
-
}) => React.ReactNode);
|
|
120
|
-
};
|
|
121
|
-
type PromptProps = {
|
|
122
|
-
message: string;
|
|
123
|
-
condition?: boolean | any;
|
|
124
|
-
children?: ReactNode;
|
|
125
|
-
};
|
|
126
|
-
declare function useLinkProps<TFrom extends string = '/', TTo extends string = ''>(options: MakeLinkPropsOptions<TFrom, TTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
127
|
-
interface LinkComponent<TProps extends Record<string, any> = {}> {
|
|
128
|
-
<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''>(props: MakeLinkOptions<TFrom, TTo> & TProps & React.RefAttributes<HTMLAnchorElement>): ReactNode;
|
|
129
|
-
}
|
|
130
|
-
declare const Link: LinkComponent;
|
|
131
|
-
declare function Navigate<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''>(props: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>): null;
|
|
132
|
-
declare const matchIdsContext: React.Context<string[]>;
|
|
133
|
-
declare const routerContext: React.Context<_tanstack_router_core.AnyRouter>;
|
|
134
|
-
type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
135
|
-
router: Router<TRouteTree>;
|
|
136
|
-
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
|
|
137
|
-
};
|
|
138
|
-
declare function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
139
|
-
select: (state: RegisteredRouter['state']) => TSelected;
|
|
140
|
-
}): TSelected;
|
|
141
|
-
declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): JSX.Element;
|
|
142
|
-
declare function useRouter(): RegisteredRouter;
|
|
143
|
-
declare function useMatches<T = RouteMatch[]>(opts?: {
|
|
144
|
-
select?: (matches: RouteMatch[]) => T;
|
|
145
|
-
}): T;
|
|
146
|
-
type StrictOrFrom<TFrom> = {
|
|
147
|
-
from: TFrom;
|
|
148
|
-
strict?: true;
|
|
149
|
-
} | {
|
|
150
|
-
from?: never;
|
|
151
|
-
strict: false;
|
|
152
|
-
};
|
|
153
|
-
declare function useMatch<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TRouteMatchState = RouteMatch<RegisteredRouter['routeTree'], RouteById<RegisteredRouter['routeTree'], TFrom>>, TSelected = TRouteMatchState>(opts: StrictOrFrom<TFrom> & {
|
|
154
|
-
select?: (match: TRouteMatchState) => TSelected;
|
|
155
|
-
}): TStrict extends true ? TRouteMatchState : TRouteMatchState | undefined;
|
|
156
|
-
type RouteFromIdOrRoute<T> = T extends ParseRoute<RegisteredRouter['routeTree']> ? T : T extends RouteIds<RegisteredRouter['routeTree']> ? RoutesById<RegisteredRouter['routeTree']>[T] : T extends string ? RouteIds<RegisteredRouter['routeTree']> : never;
|
|
157
|
-
declare function useLoader<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TLoader = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['loader'], TSelected = TLoader>(opts: StrictOrFrom<TFrom> & {
|
|
158
|
-
select?: (search: TLoader) => TSelected;
|
|
159
|
-
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
160
|
-
declare function useRouterContext<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TContext = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['context'], TSelected = TContext>(opts: StrictOrFrom<TFrom> & {
|
|
161
|
-
select?: (search: TContext) => TSelected;
|
|
162
|
-
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
163
|
-
declare function useRouteContext<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TRouteContext = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['routeContext'], TSelected = TRouteContext>(opts: StrictOrFrom<TFrom> & {
|
|
164
|
-
select?: (search: TRouteContext) => TSelected;
|
|
165
|
-
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
166
|
-
declare function useSearch<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TSearch = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['fullSearchSchema'], TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
167
|
-
select?: (search: TSearch) => TSelected;
|
|
168
|
-
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
169
|
-
declare function useParams<TFrom extends RouteIds<RegisteredRouter['routeTree']> = '/', TDefaultSelected = AllParams<RegisteredRouter['routeTree']> & RouteById<RegisteredRouter['routeTree'], TFrom>['types']['allParams'], TSelected = TDefaultSelected>(opts: StrictOrFrom<TFrom> & {
|
|
170
|
-
select?: (search: TDefaultSelected) => TSelected;
|
|
171
|
-
}): TSelected;
|
|
172
|
-
declare function useNavigate<TDefaultFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/'>(defaultOpts?: {
|
|
173
|
-
from?: TDefaultFrom;
|
|
174
|
-
}): <TFrom extends unknown = TDefaultFrom, TTo extends string = "">(opts?: NavigateOptions<any, TFrom, TTo> | undefined) => Promise<void>;
|
|
175
|
-
declare function useMatchRoute(): <TFrom extends string = "/", TTo extends string = "">(opts: MakeUseMatchRouteOptions<TFrom, TTo>) => any;
|
|
176
|
-
declare function MatchRoute<TFrom extends string = '/', TTo extends string = ''>(props: MakeMatchRouteOptions<TFrom, TTo>): any;
|
|
177
|
-
declare function Outlet(): JSX.Element | null;
|
|
178
|
-
declare function useInjectHtml(): (html: string | (() => Promise<string> | string)) => void;
|
|
179
|
-
declare function useDehydrate(): <T>(key: any, data: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
180
|
-
declare function useHydrate(): <T = unknown>(key: any) => T;
|
|
181
|
-
declare function ErrorComponent({ error }: {
|
|
182
|
-
error: any;
|
|
183
|
-
}): JSX.Element;
|
|
184
|
-
declare function useBlocker(message: string, condition?: boolean | any): void;
|
|
185
|
-
declare function Block({ message, condition, children }: PromptProps): any;
|
|
186
|
-
declare function shallow<T>(objA: T, objB: T): boolean;
|
|
187
|
-
|
|
188
|
-
declare function useScrollRestoration(options?: ScrollRestorationOptions): void;
|
|
189
|
-
declare function ScrollRestoration(props: ScrollRestorationOptions): null;
|
|
190
|
-
|
|
191
|
-
type AwaitOptions<T> = {
|
|
192
|
-
promise: DeferredPromise<T>;
|
|
193
|
-
};
|
|
194
|
-
declare function useAwaited<T>({ promise }: AwaitOptions<T>): [T];
|
|
195
|
-
declare function Await<T>(props: AwaitOptions<T> & {
|
|
196
|
-
children: (result: T) => JSX.Element;
|
|
197
|
-
}): JSX.Element;
|
|
198
|
-
|
|
199
|
-
export { AnyRouteComponent, AsyncRouteComponent, Await, AwaitOptions, Block, ErrorComponent, ErrorRouteComponent, ErrorRouteComponentProps, ErrorRouteProps, Link, LinkComponent, LinkPropsOptions, MakeLinkOptions, MakeLinkPropsOptions, MakeMatchRouteOptions, MakeUseMatchRouteOptions, MatchRoute, Navigate, Outlet, PendingRouteProps, PromptProps, RouteComponent, RouteFromIdOrRoute, RouteProps, RouterProps, RouterProvider, ScrollRestoration, SyncRouteComponent, lazyRouteComponent, matchIdsContext, routerContext, shallow, useAwaited, useBlocker, useDehydrate, useHydrate, useInjectHtml, useLinkProps, useLoader, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterContext, useRouterState, useScrollRestoration, useSearch };
|
|
3
|
+
export * from './react';
|
|
4
|
+
export * from './scroll-restoration';
|
|
5
|
+
export * from './awaited';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { NoInfer } from '@tanstack/react-store';
|
|
3
|
+
import { MatchRouteOptions, RegisteredRouter, RouterOptions, Router, RouteMatch, RouteByPath, AnyRoute, AnyRouteProps, LinkOptions, ToOptions, ResolveRelativePath, NavigateOptions, ResolveFullPath, ResolveId, AnySearchSchema, ParsePathParams, MergeParamsFromParent, RouteContext, AnyContext, UseLoaderResult, ResolveFullSearchSchema, RouteConstraints, RoutePaths, RoutesById, RouteIds, RouteById, ParseRoute, AllParams, AnyPathParams } from '@tanstack/router-core';
|
|
4
|
+
declare module '@tanstack/router-core' {
|
|
5
|
+
interface RegisterRouteComponent<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
6
|
+
RouteComponent: RouteComponent<RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
7
|
+
}
|
|
8
|
+
interface RegisterErrorRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
9
|
+
ErrorRouteComponent: RouteComponent<ErrorRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
10
|
+
}
|
|
11
|
+
interface RegisterPendingRouteComponent<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
12
|
+
PendingRouteComponent: RouteComponent<PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>>;
|
|
13
|
+
}
|
|
14
|
+
interface Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Record<ParsePathParams<TPath>, string>, TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<TParentRoute['types']['allParams'], TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
15
|
+
useMatch: <TSelected = TAllContext>(opts?: {
|
|
16
|
+
select?: (search: TAllContext) => TSelected;
|
|
17
|
+
}) => TSelected;
|
|
18
|
+
useLoader: <TSelected = TLoader>(opts?: {
|
|
19
|
+
select?: (search: TLoader) => TSelected;
|
|
20
|
+
}) => UseLoaderResult<TSelected>;
|
|
21
|
+
useContext: <TSelected = TAllContext>(opts?: {
|
|
22
|
+
select?: (search: TAllContext) => TSelected;
|
|
23
|
+
}) => TSelected;
|
|
24
|
+
useRouteContext: <TSelected = TRouteContext>(opts?: {
|
|
25
|
+
select?: (search: TRouteContext) => TSelected;
|
|
26
|
+
}) => TSelected;
|
|
27
|
+
useSearch: <TSelected = TFullSearchSchema>(opts?: {
|
|
28
|
+
select?: (search: TFullSearchSchema) => TSelected;
|
|
29
|
+
}) => TSelected;
|
|
30
|
+
useParams: <TSelected = TAllParams>(opts?: {
|
|
31
|
+
select?: (search: TAllParams) => TSelected;
|
|
32
|
+
}) => TSelected;
|
|
33
|
+
}
|
|
34
|
+
interface RegisterRouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
35
|
+
RouteProps: RouteProps<TLoader, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
36
|
+
}
|
|
37
|
+
interface RegisterPendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
38
|
+
PendingRouteProps: PendingRouteProps<TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
39
|
+
}
|
|
40
|
+
interface RegisterErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> {
|
|
41
|
+
ErrorRouteProps: ErrorRouteProps;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export type RouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = {
|
|
45
|
+
useLoader: <TStrict extends boolean = true, TSelected = TLoader>(opts?: {
|
|
46
|
+
strict?: TStrict;
|
|
47
|
+
select?: (search: TLoader) => TSelected;
|
|
48
|
+
}) => TStrict extends true ? UseLoaderResult<TSelected> : UseLoaderResult<TSelected> | undefined;
|
|
49
|
+
useMatch: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
|
|
50
|
+
strict?: TStrict;
|
|
51
|
+
select?: (search: TAllContext) => TSelected;
|
|
52
|
+
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
53
|
+
useContext: <TStrict extends boolean = true, TSelected = TAllContext>(opts?: {
|
|
54
|
+
strict?: TStrict;
|
|
55
|
+
select?: (search: TAllContext) => TSelected;
|
|
56
|
+
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
57
|
+
useRouteContext: <TStrict extends boolean = true, TSelected = TRouteContext>(opts?: {
|
|
58
|
+
strict?: TStrict;
|
|
59
|
+
select?: (search: TRouteContext) => TSelected;
|
|
60
|
+
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
61
|
+
useSearch: <TStrict extends boolean = true, TSelected = TFullSearchSchema>(opts?: {
|
|
62
|
+
strict?: TStrict;
|
|
63
|
+
select?: (search: TFullSearchSchema) => TSelected;
|
|
64
|
+
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
65
|
+
useParams: <TStrict extends boolean = true, TSelected = TAllParams>(opts?: {
|
|
66
|
+
strict?: TStrict;
|
|
67
|
+
select?: (search: TAllParams) => TSelected;
|
|
68
|
+
}) => TStrict extends true ? TSelected : TSelected | undefined;
|
|
69
|
+
};
|
|
70
|
+
export type ErrorRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = {
|
|
71
|
+
error: unknown;
|
|
72
|
+
info: {
|
|
73
|
+
componentStack: string;
|
|
74
|
+
};
|
|
75
|
+
} & Omit<RouteProps<unknown, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>, 'useLoader'>;
|
|
76
|
+
export type PendingRouteProps<TFullSearchSchema extends AnySearchSchema = AnySearchSchema, TAllParams extends AnyPathParams = AnyPathParams, TRouteContext extends AnyContext = AnyContext, TAllContext extends AnyContext = AnyContext> = Omit<RouteProps<unknown, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>, 'useLoader'>;
|
|
77
|
+
type ReactNode = any;
|
|
78
|
+
export type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.LazyExoticComponent<(props: TProps) => ReactNode>;
|
|
79
|
+
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
80
|
+
preload?: () => Promise<void>;
|
|
81
|
+
};
|
|
82
|
+
export type ErrorRouteComponent = AsyncRouteComponent<ErrorRouteComponentProps>;
|
|
83
|
+
export type ErrorRouteComponentProps = {
|
|
84
|
+
error: Error;
|
|
85
|
+
info: {
|
|
86
|
+
componentStack: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export type AnyRouteComponent = RouteComponent<AnyRouteProps>;
|
|
90
|
+
export type RouteComponent<TProps> = AsyncRouteComponent<TProps>;
|
|
91
|
+
export declare function lazyRouteComponent<T extends Record<string, any>, TKey extends keyof T = 'default'>(importer: () => Promise<T>, exportName?: TKey): T[TKey] extends (props: infer TProps) => any ? AsyncRouteComponent<TProps> : never;
|
|
92
|
+
export type LinkPropsOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = LinkOptions<RegisteredRouter['routeTree'], TFrom, TTo> & {
|
|
93
|
+
activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
94
|
+
inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
95
|
+
startTransition?: boolean;
|
|
96
|
+
};
|
|
97
|
+
export type MakeUseMatchRouteOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions;
|
|
98
|
+
export type MakeMatchRouteOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = ToOptions<RegisteredRouter['routeTree'], TFrom, TTo> & MatchRouteOptions & {
|
|
99
|
+
children?: ((params?: RouteByPath<RegisteredRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
|
100
|
+
};
|
|
101
|
+
export type MakeLinkPropsOptions<TFrom extends string = '/', TTo extends string = ''> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
102
|
+
export type MakeLinkOptions<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''> = LinkPropsOptions<TFrom, TTo> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
103
|
+
children?: React.ReactNode | ((state: {
|
|
104
|
+
isActive: boolean;
|
|
105
|
+
}) => React.ReactNode);
|
|
106
|
+
};
|
|
107
|
+
export type PromptProps = {
|
|
108
|
+
message: string;
|
|
109
|
+
condition?: boolean | any;
|
|
110
|
+
children?: ReactNode;
|
|
111
|
+
};
|
|
112
|
+
export declare function useLinkProps<TFrom extends string = '/', TTo extends string = ''>(options: MakeLinkPropsOptions<TFrom, TTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
113
|
+
export interface LinkComponent<TProps extends Record<string, any> = {}> {
|
|
114
|
+
<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''>(props: MakeLinkOptions<TFrom, TTo> & TProps & React.RefAttributes<HTMLAnchorElement>): ReactNode;
|
|
115
|
+
}
|
|
116
|
+
export declare const Link: LinkComponent;
|
|
117
|
+
export declare function Navigate<TFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/', TTo extends string = ''>(props: NavigateOptions<RegisteredRouter['routeTree'], TFrom, TTo>): null;
|
|
118
|
+
export declare const matchIdsContext: React.Context<string[]>;
|
|
119
|
+
export declare const routerContext: React.Context<import("@tanstack/router-core").AnyRouter>;
|
|
120
|
+
export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
|
|
121
|
+
router: Router<TRouteTree>;
|
|
122
|
+
context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
|
|
123
|
+
};
|
|
124
|
+
export declare function useRouterState<TSelected = RegisteredRouter['state']>(opts?: {
|
|
125
|
+
select: (state: RegisteredRouter['state']) => TSelected;
|
|
126
|
+
}): TSelected;
|
|
127
|
+
export declare function RouterProvider<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>): JSX.Element;
|
|
128
|
+
export declare function useRouter(): RegisteredRouter;
|
|
129
|
+
export declare function useMatches<T = RouteMatch[]>(opts?: {
|
|
130
|
+
select?: (matches: RouteMatch[]) => T;
|
|
131
|
+
}): T;
|
|
132
|
+
type StrictOrFrom<TFrom> = {
|
|
133
|
+
from: TFrom;
|
|
134
|
+
strict?: true;
|
|
135
|
+
} | {
|
|
136
|
+
from?: never;
|
|
137
|
+
strict: false;
|
|
138
|
+
};
|
|
139
|
+
export declare function useMatch<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TRouteMatchState = RouteMatch<RegisteredRouter['routeTree'], RouteById<RegisteredRouter['routeTree'], TFrom>>, TSelected = TRouteMatchState>(opts: StrictOrFrom<TFrom> & {
|
|
140
|
+
select?: (match: TRouteMatchState) => TSelected;
|
|
141
|
+
}): TStrict extends true ? TRouteMatchState : TRouteMatchState | undefined;
|
|
142
|
+
export type RouteFromIdOrRoute<T> = T extends ParseRoute<RegisteredRouter['routeTree']> ? T : T extends RouteIds<RegisteredRouter['routeTree']> ? RoutesById<RegisteredRouter['routeTree']>[T] : T extends string ? RouteIds<RegisteredRouter['routeTree']> : never;
|
|
143
|
+
export declare function useLoader<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TLoader = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['loader'], TSelected = TLoader>(opts: StrictOrFrom<TFrom> & {
|
|
144
|
+
select?: (search: TLoader) => TSelected;
|
|
145
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
146
|
+
export declare function useRouterContext<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TContext = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['context'], TSelected = TContext>(opts: StrictOrFrom<TFrom> & {
|
|
147
|
+
select?: (search: TContext) => TSelected;
|
|
148
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
149
|
+
export declare function useRouteContext<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TRouteContext = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['routeContext'], TSelected = TRouteContext>(opts: StrictOrFrom<TFrom> & {
|
|
150
|
+
select?: (search: TRouteContext) => TSelected;
|
|
151
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
152
|
+
export declare function useSearch<TFrom extends RouteIds<RegisteredRouter['routeTree']>, TStrict extends boolean = true, TSearch = RouteById<RegisteredRouter['routeTree'], TFrom>['types']['fullSearchSchema'], TSelected = TSearch>(opts: StrictOrFrom<TFrom> & {
|
|
153
|
+
select?: (search: TSearch) => TSelected;
|
|
154
|
+
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
155
|
+
export declare function useParams<TFrom extends RouteIds<RegisteredRouter['routeTree']> = '/', TDefaultSelected = AllParams<RegisteredRouter['routeTree']> & RouteById<RegisteredRouter['routeTree'], TFrom>['types']['allParams'], TSelected = TDefaultSelected>(opts: StrictOrFrom<TFrom> & {
|
|
156
|
+
select?: (search: TDefaultSelected) => TSelected;
|
|
157
|
+
}): TSelected;
|
|
158
|
+
export declare function useNavigate<TDefaultFrom extends RoutePaths<RegisteredRouter['routeTree']> = '/'>(defaultOpts?: {
|
|
159
|
+
from?: TDefaultFrom;
|
|
160
|
+
}): <TFrom extends unknown = TDefaultFrom, TTo extends string = "">(opts?: NavigateOptions<any, TFrom, TTo> | undefined) => Promise<void>;
|
|
161
|
+
export declare function useMatchRoute(): <TFrom extends string = "/", TTo extends string = "">(opts: MakeUseMatchRouteOptions<TFrom, TTo>) => any;
|
|
162
|
+
export declare function MatchRoute<TFrom extends string = '/', TTo extends string = ''>(props: MakeMatchRouteOptions<TFrom, TTo>): any;
|
|
163
|
+
export declare function Outlet(): JSX.Element | null;
|
|
164
|
+
export declare function useInjectHtml(): (html: string | (() => Promise<string> | string)) => void;
|
|
165
|
+
export declare function useDehydrate(): <T>(key: any, data: T | (() => T | Promise<T>)) => () => T | undefined;
|
|
166
|
+
export declare function useHydrate(): <T = unknown>(key: any) => T;
|
|
167
|
+
export declare function ErrorComponent({ error }: {
|
|
168
|
+
error: any;
|
|
169
|
+
}): JSX.Element;
|
|
170
|
+
export declare function useBlocker(message: string, condition?: boolean | any): void;
|
|
171
|
+
export declare function Block({ message, condition, children }: PromptProps): any;
|
|
172
|
+
export declare function shallow<T>(objA: T, objB: T): boolean;
|
|
173
|
+
export {};
|
|
@@ -869,6 +869,8 @@
|
|
|
869
869
|
//
|
|
870
870
|
|
|
871
871
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
872
|
+
const visibilityChangeEvent = 'visibilitychange';
|
|
873
|
+
const focusEvent = 'focus';
|
|
872
874
|
class Router {
|
|
873
875
|
#unsubHistory;
|
|
874
876
|
resetNextScroll = false;
|
|
@@ -945,12 +947,26 @@
|
|
|
945
947
|
this.__store.setState(s => Object.assign(s, getInitialRouterState()));
|
|
946
948
|
};
|
|
947
949
|
mount = () => {
|
|
948
|
-
//
|
|
949
|
-
//
|
|
950
|
+
// addEventListener does not exist in React Native, but window does
|
|
951
|
+
// In the future, we might need to invert control here for more adapters
|
|
952
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
953
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
954
|
+
window.addEventListener(visibilityChangeEvent, this.#onFocus, false);
|
|
955
|
+
window.addEventListener(focusEvent, this.#onFocus, false);
|
|
956
|
+
}
|
|
950
957
|
this.safeLoad();
|
|
951
|
-
|
|
958
|
+
return () => {
|
|
959
|
+
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
960
|
+
window.removeEventListener(visibilityChangeEvent, this.#onFocus);
|
|
961
|
+
window.removeEventListener(focusEvent, this.#onFocus);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
};
|
|
965
|
+
#onFocus = () => {
|
|
966
|
+
if (this.options.refetchOnWindowFocus ?? true) {
|
|
967
|
+
this.reload();
|
|
968
|
+
}
|
|
952
969
|
};
|
|
953
|
-
|
|
954
970
|
update = opts => {
|
|
955
971
|
this.options = {
|
|
956
972
|
...this.options,
|
|
@@ -1021,7 +1037,6 @@
|
|
|
1021
1037
|
};
|
|
1022
1038
|
|
|
1023
1039
|
// Cancel any pending matches
|
|
1024
|
-
// this.cancelMatches()
|
|
1025
1040
|
|
|
1026
1041
|
let pendingMatches;
|
|
1027
1042
|
this.#emit({
|
|
@@ -1064,6 +1079,9 @@
|
|
|
1064
1079
|
if (latestPromise = checkLatest()) {
|
|
1065
1080
|
return latestPromise;
|
|
1066
1081
|
}
|
|
1082
|
+
const exitingMatchIds = this.state.matchIds.filter(id => !this.state.pendingMatchIds.includes(id));
|
|
1083
|
+
const enteringMatchIds = this.state.pendingMatchIds.filter(id => !this.state.matchIds.includes(id));
|
|
1084
|
+
const stayingMatchIds = this.state.matchIds.filter(id => this.state.pendingMatchIds.includes(id));
|
|
1067
1085
|
this.__store.setState(s => ({
|
|
1068
1086
|
...s,
|
|
1069
1087
|
status: 'idle',
|
|
@@ -1071,6 +1089,13 @@
|
|
|
1071
1089
|
matchIds: s.pendingMatchIds,
|
|
1072
1090
|
pendingMatchIds: []
|
|
1073
1091
|
}));
|
|
1092
|
+
[[exitingMatchIds, 'onLeave'], [enteringMatchIds, 'onEnter'], [stayingMatchIds, 'onTransition']].forEach(([matchIds, hook]) => {
|
|
1093
|
+
matchIds.forEach(id => {
|
|
1094
|
+
const match = this.getRouteMatch(id);
|
|
1095
|
+
const route = this.getRoute(match.routeId);
|
|
1096
|
+
route.options[hook]?.(match);
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
1074
1099
|
this.#emit({
|
|
1075
1100
|
type: 'onLoad',
|
|
1076
1101
|
from: prevLocation,
|
|
@@ -1087,6 +1112,9 @@
|
|
|
1087
1112
|
}
|
|
1088
1113
|
});
|
|
1089
1114
|
this.latestLoadPromise = promise;
|
|
1115
|
+
this.latestLoadPromise.then(() => {
|
|
1116
|
+
this.cleanMatches();
|
|
1117
|
+
});
|
|
1090
1118
|
return this.latestLoadPromise;
|
|
1091
1119
|
};
|
|
1092
1120
|
#mergeMatches = (prevMatchesById, nextMatches) => {
|
|
@@ -1131,7 +1159,7 @@
|
|
|
1131
1159
|
const now = Date.now();
|
|
1132
1160
|
const outdatedMatchIds = Object.values(this.state.matchesById).filter(match => {
|
|
1133
1161
|
const route = this.getRoute(match.routeId);
|
|
1134
|
-
return !this.state.matchIds.includes(match.id) && !this.state.pendingMatchIds.includes(match.id) && match.
|
|
1162
|
+
return !this.state.matchIds.includes(match.id) && !this.state.pendingMatchIds.includes(match.id) && (match.preloadMaxAge > -1 ? match.updatedAt + match.preloadMaxAge < now : true) && (route.options.gcMaxAge ? match.updatedAt + route.options.gcMaxAge < now : true);
|
|
1135
1163
|
}).map(d => d.id);
|
|
1136
1164
|
if (outdatedMatchIds.length) {
|
|
1137
1165
|
this.__store.setState(s => {
|
|
@@ -1219,8 +1247,8 @@
|
|
|
1219
1247
|
params: routeParams,
|
|
1220
1248
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
1221
1249
|
updatedAt: Date.now(),
|
|
1222
|
-
|
|
1223
|
-
|
|
1250
|
+
maxAge: -1,
|
|
1251
|
+
preloadMaxAge: -1,
|
|
1224
1252
|
routeSearch: {},
|
|
1225
1253
|
search: {},
|
|
1226
1254
|
status: hasLoaders ? 'pending' : 'success',
|
|
@@ -1316,11 +1344,10 @@
|
|
|
1316
1344
|
paramsError: match.paramsError,
|
|
1317
1345
|
searchError: match.searchError,
|
|
1318
1346
|
params: match.params,
|
|
1319
|
-
|
|
1347
|
+
preloadMaxAge: 0
|
|
1320
1348
|
}));
|
|
1321
1349
|
});
|
|
1322
1350
|
}
|
|
1323
|
-
this.cleanMatches();
|
|
1324
1351
|
let firstBadMatchIndex;
|
|
1325
1352
|
|
|
1326
1353
|
// Check each match middleware to see if the route can be accessed
|
|
@@ -1382,8 +1409,7 @@
|
|
|
1382
1409
|
matchPromises.push((async () => {
|
|
1383
1410
|
const parentMatchPromise = matchPromises[index - 1];
|
|
1384
1411
|
const route = this.getRoute(match.routeId);
|
|
1385
|
-
if (match.isFetching || match.status === 'success' && !
|
|
1386
|
-
matchId: match.id,
|
|
1412
|
+
if (match.isFetching || match.status === 'success' && !isMatchInvalid(match, {
|
|
1387
1413
|
preload: opts?.preload
|
|
1388
1414
|
})) {
|
|
1389
1415
|
return this.getRouteMatch(match.id)?.loadPromise;
|
|
@@ -1456,7 +1482,6 @@
|
|
|
1456
1482
|
})());
|
|
1457
1483
|
});
|
|
1458
1484
|
await Promise.all(matchPromises);
|
|
1459
|
-
this.cleanMatches();
|
|
1460
1485
|
};
|
|
1461
1486
|
reload = () => {
|
|
1462
1487
|
return this.navigate({
|
|
@@ -1641,7 +1666,7 @@
|
|
|
1641
1666
|
dehydrate = () => {
|
|
1642
1667
|
return {
|
|
1643
1668
|
state: {
|
|
1644
|
-
dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', '
|
|
1669
|
+
dehydratedMatches: this.state.matches.map(d => pick(d, ['fetchedAt', 'invalid', 'preloadMaxAge', 'maxAge', 'id', 'loaderData', 'status', 'updatedAt']))
|
|
1645
1670
|
}
|
|
1646
1671
|
};
|
|
1647
1672
|
};
|
|
@@ -1880,7 +1905,6 @@
|
|
|
1880
1905
|
...next.state
|
|
1881
1906
|
});
|
|
1882
1907
|
this.resetNextScroll = location.resetScroll ?? true;
|
|
1883
|
-
console.log('resetScroll', this.resetNextScroll);
|
|
1884
1908
|
return this.latestLoadPromise;
|
|
1885
1909
|
};
|
|
1886
1910
|
getRouteMatch = id => {
|
|
@@ -1905,17 +1929,17 @@
|
|
|
1905
1929
|
if (!match) return;
|
|
1906
1930
|
const route = this.getRoute(match.routeId);
|
|
1907
1931
|
const updatedAt = opts?.updatedAt ?? Date.now();
|
|
1908
|
-
const
|
|
1909
|
-
const
|
|
1932
|
+
const preloadMaxAge = opts?.maxAge ?? route.options.preloadMaxAge ?? this.options.defaultPreloadMaxAge ?? 5000;
|
|
1933
|
+
const maxAge = opts?.maxAge ?? route.options.maxAge ?? this.options.defaultMaxAge ?? -1;
|
|
1910
1934
|
this.setRouteMatch(id, s => ({
|
|
1911
1935
|
...s,
|
|
1912
1936
|
error: undefined,
|
|
1913
1937
|
status: 'success',
|
|
1914
1938
|
isFetching: false,
|
|
1915
|
-
updatedAt:
|
|
1939
|
+
updatedAt: updatedAt,
|
|
1916
1940
|
loaderData: functionalUpdate(updater, s.loaderData),
|
|
1917
|
-
|
|
1918
|
-
|
|
1941
|
+
preloadMaxAge,
|
|
1942
|
+
maxAge
|
|
1919
1943
|
}));
|
|
1920
1944
|
};
|
|
1921
1945
|
invalidate = async opts => {
|
|
@@ -1946,20 +1970,6 @@
|
|
|
1946
1970
|
return this.reload();
|
|
1947
1971
|
}
|
|
1948
1972
|
};
|
|
1949
|
-
getIsInvalid = opts => {
|
|
1950
|
-
if (!opts?.matchId) {
|
|
1951
|
-
return !!this.state.matches.find(d => this.getIsInvalid({
|
|
1952
|
-
matchId: d.id,
|
|
1953
|
-
preload: opts?.preload
|
|
1954
|
-
}));
|
|
1955
|
-
}
|
|
1956
|
-
const match = this.getRouteMatch(opts?.matchId);
|
|
1957
|
-
if (!match) {
|
|
1958
|
-
return false;
|
|
1959
|
-
}
|
|
1960
|
-
const now = Date.now();
|
|
1961
|
-
return match.invalid || (opts?.preload ? match.preloadInvalidAt : match.invalidAt) < now;
|
|
1962
|
-
};
|
|
1963
1973
|
}
|
|
1964
1974
|
|
|
1965
1975
|
// Detect if we're in the DOM
|
|
@@ -2005,6 +2015,16 @@
|
|
|
2005
2015
|
return imported[key || 'default'](...args);
|
|
2006
2016
|
};
|
|
2007
2017
|
}
|
|
2018
|
+
function isMatchInvalid(match, opts) {
|
|
2019
|
+
const now = Date.now();
|
|
2020
|
+
if (match.invalid) {
|
|
2021
|
+
return true;
|
|
2022
|
+
}
|
|
2023
|
+
if (opts?.preload) {
|
|
2024
|
+
return match.preloadMaxAge < 0 ? false : match.updatedAt + match.preloadMaxAge < now;
|
|
2025
|
+
}
|
|
2026
|
+
return match.maxAge < 0 ? false : match.updatedAt + match.maxAge < now;
|
|
2027
|
+
}
|
|
2008
2028
|
|
|
2009
2029
|
const windowKey = 'window';
|
|
2010
2030
|
const delimiter = '___';
|
|
@@ -2806,6 +2826,7 @@
|
|
|
2806
2826
|
exports.interpolatePath = interpolatePath;
|
|
2807
2827
|
exports.invariant = invariant;
|
|
2808
2828
|
exports.isDehydratedDeferred = isDehydratedDeferred;
|
|
2829
|
+
exports.isMatchInvalid = isMatchInvalid;
|
|
2809
2830
|
exports.isPlainObject = isPlainObject;
|
|
2810
2831
|
exports.isRedirect = isRedirect;
|
|
2811
2832
|
exports.joinPaths = joinPaths;
|