@tanstack/router-core 0.0.1-alpha.0 → 0.0.1-alpha.1

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.
@@ -1,10 +0,0 @@
1
- import { Route } from '.';
2
- export declare function createRoutes<TRoutes extends Route[]>(routes: Narrow<TRoutes>): Try<TRoutes, [], NarrowRaw<TRoutes>>;
3
- declare type Narrow<T> = Try<T, [], NarrowRaw<T>>;
4
- declare type Try<A, B, C> = A extends B ? A : C;
5
- declare type NarrowRaw<T> = (T extends [] ? [] : never) | (T extends string | number | bigint | boolean ? T : never) | {
6
- [K in keyof T]: T[K] extends Function ? T[K] : NarrowRaw<T[K]>;
7
- };
8
- declare type TrimPath<T extends string> = '' extends T ? '' : T extends `/${infer U}` ? TrimPath<U> : T extends `${infer U}/` ? TrimPath<U> : T;
9
- export declare type ParsePathParam<T, N = never> = T extends string ? TrimPath<T> extends `:${infer U}` ? U : N : never;
10
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export declare function encode(obj: any, pfx?: string): string;
2
- export declare function decode(str: any): {};
@@ -1,59 +0,0 @@
1
- import * as React from 'react';
2
- import { Router, RouterOptions, RouteMatch, RouteParams, NavigateOptions, MatchLocation, MatchRouteOptions, LinkOptions, RouteDef, RoutesInfo } from '@tanstack/router-core';
3
- export * from '@tanstack/router-core';
4
- declare module '@tanstack/router-core' {
5
- interface FrameworkGenerics {
6
- Element: React.ReactNode;
7
- AsyncElement: (opts: {
8
- params: Record<string, string>;
9
- }) => Promise<React.ReactNode>;
10
- SyncOrAsyncElement: React.ReactNode | FrameworkGenerics['AsyncElement'];
11
- LinkProps: React.HTMLAttributes<unknown>;
12
- }
13
- }
14
- export declare type PromptProps = {
15
- message: string;
16
- when?: boolean | any;
17
- children?: React.ReactNode;
18
- };
19
- export declare type MatchesProviderProps = {
20
- value: RouteMatch[];
21
- children: React.ReactNode;
22
- };
23
- export declare function MatchesProvider(props: MatchesProviderProps): JSX.Element;
24
- export declare type RouterProps<TRouteDefs extends RouteDef = RouteDef> = RouterOptions<TRouteDefs> & {
25
- router: Router<TRouteDefs>;
26
- children?: React.ReactNode;
27
- };
28
- export declare class ReactRouter<TRouteDefs extends RouteDef = RouteDef, TRoutesInfo extends RoutesInfo<TRouteDefs> = RoutesInfo<TRouteDefs>> extends Router<TRouteDefs, TRoutesInfo> {
29
- constructor(options: RouterOptions<TRouteDefs>);
30
- }
31
- export declare function RouterProvider<TRouteDefs extends RouteDef = RouteDef>({ children, router, ...rest }: RouterProps<TRouteDefs>): JSX.Element;
32
- export declare function useRouter(): Router;
33
- export declare function useMatches(): RouteMatch[];
34
- export declare function useParentMatches(): RouteMatch[];
35
- export declare function useMatch<T>(): RouteMatch;
36
- export declare function useLoaderData(): unknown;
37
- export declare function useAction<TPayload = unknown, TResponse = unknown, TError = unknown>(opts?: Pick<NavigateOptions, 'to' | 'from'>): import("@tanstack/router-core").Action<TPayload, TResponse>;
38
- export declare function useMatchRoute(): (matchLocation: MatchLocation, opts?: MatchRouteOptions | undefined) => RouteParams | undefined;
39
- export declare type MatchRouteProps = MatchLocation & MatchRouteOptions & {
40
- children: React.ReactNode | ((routeParams?: RouteParams) => React.ReactNode);
41
- };
42
- export declare function MatchRoute({ children, pending, caseSensitive, ...rest }: MatchRouteProps): JSX.Element;
43
- export declare function useLoadRoute(): (navigateOpts: NavigateOptions, loaderOpts: {
44
- maxAge: number;
45
- }) => Promise<RouteMatch<string, string, {}, {}, unknown, unknown, {}, {}, Record<never, string>>[]>;
46
- export declare function useInvalidateRoute(): (navigateOpts?: MatchLocation | undefined) => Promise<void>;
47
- export declare function useNavigate(): (options: NavigateOptions) => Promise<void>;
48
- export declare function Navigate(options: NavigateOptions): null;
49
- export declare function Outlet(): JSX.Element | null;
50
- export declare function useResolvePath(): (path: string) => string;
51
- export declare function useSearch(): {};
52
- export declare type LinkProps<TRoutesInfo extends RoutesInfo = RoutesInfo, TRouteId extends keyof TRoutesInfo['routesById'] = any> = LinkOptions & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'children' | keyof LinkOptions> & {
53
- _ref?: React.Ref<HTMLAnchorElement>;
54
- children?: React.ReactNode | ((state: {
55
- isActive: boolean;
56
- }) => React.ReactNode);
57
- };
58
- export declare function useLink(opts: LinkOptions): import("@tanstack/router-core").LinkInfo | null;
59
- export declare function Link<TRoutesInfo>(props: LinkProps): JSX.Element;
@@ -1 +0,0 @@
1
- export {};
@@ -1,504 +0,0 @@
1
- import { createHashHistory, createBrowserHistory, createMemoryHistory, BrowserHistory, MemoryHistory, History, HashHistory } from 'history';
2
- export { createHashHistory, createBrowserHistory, createMemoryHistory };
3
- export declare type NoInfer<T> = [T][T extends any ? 0 : never];
4
- export declare type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
5
- export declare type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
6
- export declare type IsKnown<T, Y, N> = unknown extends T ? N : Y;
7
- export declare type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
8
- export declare type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
9
- export declare type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
10
- export declare type PickExtra<T, K> = Expand<{
11
- [TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
12
- }>;
13
- declare type PickRequired<T> = {
14
- [K in keyof T as undefined extends T[K] ? never : K]: T[K];
15
- };
16
- declare type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
17
- declare type Expand<T> = T extends object ? T extends infer O ? {
18
- [K in keyof O]: O[K];
19
- } : never : T;
20
- export interface FrameworkGenerics {
21
- }
22
- export interface RouteConfig<TId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = AnyLoaderData, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
23
- id: TId;
24
- path: NoInfer<TPath>;
25
- fullPath: TFullPath;
26
- options: RouteOptions<TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
27
- children?: TKnownChildren;
28
- addChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
29
- error: 'Invalid route detected';
30
- route: TNewChildren;
31
- }) => RouteConfig<TId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
32
- }
33
- declare type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentAllLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TPath extends string, TRouteLoaderData extends AnyLoaderData, TActionPayload, TActionResponse, TSearchSchema extends AnySearchSchema = AnySearchSchema, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams> = AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams>, TKnownChildren extends RouteConfig[] = RouteConfig[]>(options?: TIsRoot extends true ? Omit<RouteOptions<TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
34
- path?: never;
35
- } : RouteOptions<TPath, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, children?: TKnownChildren, isRoot?: boolean, parentId?: string) => RouteConfig<RouteId<TParentId, TPath>, TPath, RouteIdToPath<RouteId<TParentId, TPath>>, TRouteLoaderData, Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
36
- export declare const createRouteConfig: CreateRouteConfigFn<true>;
37
- export interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> {
38
- }
39
- export interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
40
- }
41
- export interface AnyAllRouteInfo {
42
- routeConfig: AnyRouteConfig;
43
- routeInfo: AnyRouteInfo;
44
- routeInfoById: Record<string, AnyRouteInfo>;
45
- routeInfoByFullPath: Record<string, AnyRouteInfo>;
46
- fullPath: string;
47
- }
48
- export interface DefaultAllRouteInfo {
49
- routeConfig: RouteConfig;
50
- routeInfo: RouteInfo;
51
- routeInfoById: Record<string, RouteInfo>;
52
- routeInfoByFullPath: Record<string, RouteInfo>;
53
- fullPath: string;
54
- }
55
- export interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
56
- }
57
- export interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any> = RouteInfo> {
58
- routeConfig: TRouteConfig;
59
- routeInfo: TRouteInfo;
60
- routeInfoById: {
61
- [TInfo in TRouteInfo as TInfo['id']]: TInfo;
62
- };
63
- routeInfoByFullPath: {
64
- [TInfo in TRouteInfo as TInfo['id'] extends RootRouteId ? never : RouteIdToPath<TInfo['id']>]: TInfo;
65
- };
66
- fullPath: RouteIdToPath<TRouteInfo['id']>;
67
- }
68
- export interface AnyRoute extends Route<any, any> {
69
- }
70
- export interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any> {
71
- }
72
- declare type RouteIdToPath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
73
- declare type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
74
- declare type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
75
- [TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
76
- }> : never : never;
77
- declare type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
78
- id: TId;
79
- } extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
80
- export declare type Values<O> = O[ValueKeys<O>];
81
- export declare type ValueKeys<O> = Extract<keyof O, PropertyKey>;
82
- export declare type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TPath, infer TFullPath, infer TRouteLoaderData, infer TLoaderData, infer TActionPayload, infer TActionResponse, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TId ? never : RouteInfo<TId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
83
- export interface RouteInfo<TId extends string = string, TPath extends string = string, TFullPath extends {} = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> {
84
- id: TId;
85
- path: TPath;
86
- fullPath: TFullPath;
87
- routeLoaderData: TRouteLoaderData;
88
- loaderData: TLoaderData;
89
- actionPayload: TActionPayload;
90
- actionResponse: TActionResponse;
91
- searchSchema: TSearchSchema;
92
- fullSearchSchema: TFullSearchSchema;
93
- parentParams: TParentParams;
94
- params: TParams;
95
- allParams: TAllParams;
96
- options: RouteOptions<TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
97
- }
98
- declare type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
99
- [K in A]: DeepAwaited<B>;
100
- } : T;
101
- export declare const rootRouteId: "__root__";
102
- export declare type RootRouteId = typeof rootRouteId;
103
- declare type RouteId<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`;
104
- declare type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
105
- declare type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
106
- declare type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
107
- declare type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
108
- export declare type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
109
- export declare type PathParamMask<TRoutePath extends string> = TRoutePath extends `${infer L}/:${infer C}/${infer R}` ? PathParamMask<`${L}/${string}/${R}`> : TRoutePath extends `${infer L}/:${infer C}` ? PathParamMask<`${L}/${string}`> : TRoutePath;
110
- declare type Split<S, TTrailing = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TTrailing extends true ? CleanPath<S> extends `${infer T}/` ? [T, '/'] : CleanPath<S> extends `/${infer U}` ? ['/', U] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [S] : never : never;
111
- declare type Join<T> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}/${Join<Tail>}`> : never;
112
- export declare type AnySearchSchema = {};
113
- export declare type AnyLoaderData = {};
114
- export declare type AnyPathParams = {};
115
- export interface RouteMeta {
116
- }
117
- export interface LocationState {
118
- }
119
- declare type Timeout = ReturnType<typeof setTimeout>;
120
- export declare type SearchSerializer = (searchObj: Record<string, any>) => string;
121
- export declare type SearchParser = (searchStr: string) => Record<string, any>;
122
- export declare type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
123
- export interface Location<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
124
- href: string;
125
- pathname: string;
126
- search: TSearchObj;
127
- searchStr: string;
128
- state: TState;
129
- hash: string;
130
- key?: string;
131
- }
132
- export interface FromLocation {
133
- pathname: string;
134
- search?: unknown;
135
- key?: string;
136
- hash?: string;
137
- }
138
- export declare type PickExtract<T, U> = {
139
- [K in keyof T as T[K] extends U ? K : never]: T[K];
140
- };
141
- export declare type PickExclude<T, U> = {
142
- [K in keyof T as T[K] extends U ? never : K]: T[K];
143
- };
144
- export declare type SearchSchemaValidator<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
145
- error: 'Top level search params cannot be redefined by child routes!';
146
- keys: keyof TReturn & keyof TParentSchema;
147
- } : TReturn;
148
- export declare type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
149
- export declare type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
150
- [Key in keyof TParentParams]?: DefinedPathParamWarning;
151
- };
152
- export declare type RouteOptions<TPath extends string = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> = {
153
- path: TPath;
154
- caseSensitive?: boolean;
155
- validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
156
- preSearchFilters?: SearchFilter<TFullSearchSchema>[];
157
- postSearchFilters?: SearchFilter<TFullSearchSchema>[];
158
- pendingMs?: number;
159
- pendingMinMs?: number;
160
- } & ({
161
- parseParams?: never;
162
- stringifyParams?: never;
163
- } | {
164
- parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
165
- stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
166
- }) & RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams> & {
167
- import?: (opts: {
168
- params: AnyPathParams;
169
- }) => Promise<RouteLoaders<TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TFullSearchSchema, TAllParams>>;
170
- } & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
171
- export interface RouteLoaders<TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
172
- element?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
173
- errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
174
- catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
175
- pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement', NoInfer<TLoaderData>>;
176
- loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
177
- action?: ActionFn<TActionPayload, TActionResponse>;
178
- useErrorBoundary?: boolean;
179
- onMatch?: (matchContext: {
180
- params: TAllParams;
181
- search: TFullSearchSchema;
182
- }) => void | undefined | ((match: {
183
- params: TAllParams;
184
- search: TFullSearchSchema;
185
- }) => void);
186
- onTransition?: (match: {
187
- params: TAllParams;
188
- search: TFullSearchSchema;
189
- }) => void;
190
- meta?: RouteMeta;
191
- }
192
- export declare type SearchFilter<T, U = T> = (prev: T) => U;
193
- export interface MatchLocation {
194
- to?: string | number | null;
195
- fuzzy?: boolean;
196
- caseSensitive?: boolean;
197
- from?: string;
198
- fromCurrent?: boolean;
199
- }
200
- export declare type SearchPredicate<TSearch extends AnySearchSchema = {}> = (search: TSearch) => any;
201
- export declare type LoaderFn<TRouteLoaderData extends AnyLoaderData, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: {
202
- params: TAllParams;
203
- search: TFullSearchSchema;
204
- signal?: AbortSignal;
205
- }) => Promise<TRouteLoaderData>;
206
- export declare type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
207
- export declare type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
208
- export interface RouterState {
209
- status: 'idle' | 'loading';
210
- location: Location;
211
- matches: RouteMatch[];
212
- lastUpdated: number;
213
- loaderData: unknown;
214
- action?: ActionState;
215
- actions: Record<string, Action>;
216
- pending?: PendingState;
217
- }
218
- export interface PendingState {
219
- location: Location;
220
- matches: RouteMatch[];
221
- }
222
- export declare type ListenerFn = () => void;
223
- export interface Segment {
224
- type: 'pathname' | 'param' | 'wildcard';
225
- value: string;
226
- }
227
- declare type GetFrameworkGeneric<U, TData = unknown> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
228
- export interface __Experimental__RouterSnapshot {
229
- location: Location;
230
- matches: SnapshotRouteMatch<unknown>[];
231
- }
232
- export interface SnapshotRouteMatch<TData> {
233
- matchId: string;
234
- loaderData: TData;
235
- }
236
- export interface BuildNextOptions {
237
- to?: string | number | null;
238
- params?: true | Updater<Record<string, any>>;
239
- search?: true | Updater<unknown>;
240
- hash?: true | Updater<string>;
241
- key?: string;
242
- from?: string;
243
- fromCurrent?: boolean;
244
- __preSearchFilters?: SearchFilter<any>[];
245
- __postSearchFilters?: SearchFilter<any>[];
246
- }
247
- interface ActiveOptions {
248
- exact?: boolean;
249
- includeHash?: boolean;
250
- }
251
- export declare type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
252
- declare type Listener = () => void;
253
- export interface MatchRouteOptions {
254
- pending: boolean;
255
- caseSensitive?: boolean;
256
- }
257
- export declare type LinkInfo = {
258
- type: 'external';
259
- href: string;
260
- } | {
261
- type: 'internal';
262
- next: Location;
263
- handleFocus: (e: any) => void;
264
- handleClick: (e: any) => void;
265
- handleEnter: (e: any) => void;
266
- handleLeave: (e: any) => void;
267
- isActive: boolean;
268
- disabled?: boolean;
269
- };
270
- export declare type PreloadCacheEntry = {
271
- maxAge: number;
272
- match: RouteMatch;
273
- };
274
- export interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
275
- history?: BrowserHistory | MemoryHistory | HashHistory;
276
- stringifySearch?: SearchSerializer;
277
- parseSearch?: SearchParser;
278
- filterRoutes?: FilterRoutesFn;
279
- defaultLinkPreload?: false | 'intent';
280
- defaultLinkPreloadMaxAge?: number;
281
- defaultLinkPreloadDelay?: number;
282
- useErrorBoundary?: boolean;
283
- defaultElement?: GetFrameworkGeneric<'Element'>;
284
- defaultErrorElement?: GetFrameworkGeneric<'Element'>;
285
- defaultCatchElement?: GetFrameworkGeneric<'Element'>;
286
- defaultPendingElement?: GetFrameworkGeneric<'Element'>;
287
- defaultPendingMs?: number;
288
- defaultPendingMinMs?: number;
289
- caseSensitive?: boolean;
290
- __experimental__snapshot?: __Experimental__RouterSnapshot;
291
- routeConfig?: TRouteConfig;
292
- basepath?: string;
293
- createRouter?: (router: Router<any, any>) => void;
294
- createRoute?: (opts: {
295
- route: AnyRoute;
296
- router: Router<any, any>;
297
- }) => void;
298
- }
299
- export interface Action<TPayload = unknown, TResponse = unknown> {
300
- submit: (submission?: TPayload) => Promise<TResponse>;
301
- latest?: ActionState;
302
- pending: ActionState<TPayload, TResponse>[];
303
- }
304
- export interface ActionState<TPayload = unknown, TResponse = unknown> {
305
- submittedAt: number;
306
- status: 'idle' | 'pending' | 'success' | 'error';
307
- submission: TPayload;
308
- data?: TResponse;
309
- error?: unknown;
310
- }
311
- declare type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
312
- [K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
313
- };
314
- export declare type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['fullPath'] ? string : TAllRouteInfo['fullPath']);
315
- export interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
316
- options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
317
- basepath: string;
318
- allRouteInfo: TAllRouteInfo;
319
- listeners: Listener[];
320
- location: Location;
321
- navigateTimeout?: Timeout;
322
- nextAction?: 'push' | 'replace';
323
- state: RouterState;
324
- routeTree: Route<TAllRouteInfo, RouteInfo>;
325
- routesById: RoutesById<TAllRouteInfo>;
326
- navigationPromise: Promise<void>;
327
- startedLoadingAt: number;
328
- destroy: () => void;
329
- resolveNavigation: () => void;
330
- subscribe: (listener: Listener) => () => void;
331
- notify: () => void;
332
- mount: () => Promise<void>;
333
- update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
334
- buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
335
- parseLocation: (location: History['location'], previousLocation?: Location) => Location;
336
- buildLocation: (dest: BuildNextOptions) => Location;
337
- commitLocation: (next: Location, replace?: boolean) => Promise<void>;
338
- buildNext: (opts: BuildNextOptions) => Location;
339
- cancelMatches: () => void;
340
- loadLocation: (next?: Location) => Promise<void>;
341
- preloadCache: Record<string, PreloadCacheEntry>;
342
- cleanPreloadCache: () => void;
343
- getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
344
- loadRoute: (navigateOpts: BuildNextOptions, loaderOpts: {
345
- maxAge: number;
346
- }) => Promise<RouteMatch[]>;
347
- matchRoutes: (pathname: string, opts?: {
348
- strictParseParams?: boolean;
349
- }) => RouteMatch[];
350
- loadMatches: (resolvedMatches: RouteMatch[], loaderOpts?: {
351
- withPending?: boolean;
352
- } & ({
353
- preload: true;
354
- maxAge: number;
355
- } | {
356
- preload?: false;
357
- maxAge?: never;
358
- })) => Promise<RouteMatch[]>;
359
- invalidateRoute: (opts: MatchLocation) => void;
360
- reload: () => Promise<void>;
361
- resolvePath: (from: string, path: string) => string;
362
- _navigate: (location: BuildNextOptions & {
363
- replace?: boolean;
364
- }) => Promise<void>;
365
- navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
366
- matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
367
- buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
368
- __experimental__createSnapshot: () => __Experimental__RouterSnapshot;
369
- }
370
- export declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
371
- export interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
372
- routeId: TRouteInfo['id'];
373
- routePath: TRouteInfo['path'];
374
- fullPath: TRouteInfo['fullPath'];
375
- parentRoute?: AnyRoute;
376
- childRoutes?: AnyRoute[];
377
- options: RouteOptions;
378
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
379
- buildLink: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => LinkInfo;
380
- matchRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>>(matchLocation: Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>, opts?: MatchRouteOptions) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams'];
381
- navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>) => Promise<void>;
382
- action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
383
- }
384
- export declare function createRoute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(routeConfig: RouteConfig, options: TRouteInfo['options'], parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>): Route<TAllRouteInfo, TRouteInfo>;
385
- export declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
386
- ...Split<ResolveRelativePath<TFrom, TTo>, false>,
387
- ...infer TToRest
388
- ] ? `${CleanPath<Join<[
389
- ...Split<TTo, false>,
390
- ...(TToRest | (Split<ResolveRelativePath<TFrom, TTo>, false>['length'] extends 1 ? never : ['../']))
391
- ]>>}` : never : TTo extends `./${infer RestTTo}` ? SplitPaths extends [
392
- ...Split<TFrom, false>,
393
- ...Split<RestTTo, false>,
394
- ...infer RestPath
395
- ] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
396
- export declare type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
397
- replace?: boolean;
398
- };
399
- export declare type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
400
- to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
401
- hash?: Updater<string>;
402
- from?: TFrom;
403
- } & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
404
- export declare type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['fullPath'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
405
- export declare type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeInfo']['id'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
406
- export declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
407
- target?: HTMLAnchorElement['target'];
408
- activeOptions?: ActiveOptions;
409
- preload?: false | 'intent';
410
- preloadMaxAge?: number;
411
- preloadDelay?: number;
412
- disabled?: boolean;
413
- };
414
- export declare type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['fullPath'] ? {} : {
415
- Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
416
- 'Valid Route Paths': TAllRouteInfo['fullPath'];
417
- } : {} : {};
418
- export declare type ResolveRelativePath<TFrom, TTo = '.', TRooted = false> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
419
- export declare type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
420
- export declare type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
421
- declare type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
422
- search?: SearchReducer<TFromSchema, TToSchema>;
423
- } : keyof PickRequired<TToSchema> extends never ? {
424
- search?: SearchReducer<TFromSchema, TToSchema>;
425
- } : {
426
- search: SearchReducer<TFromSchema, TToSchema>;
427
- };
428
- declare type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
429
- declare type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
430
- params?: ParamsReducer<TFromParams, TToParams>;
431
- } : AnyPathParams extends TToParams ? {
432
- params?: ParamsReducer<TFromParams, Record<string, never>>;
433
- } : {
434
- params: ParamsReducer<TFromParams, TToParams>;
435
- };
436
- declare type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
437
- export interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
438
- matchId: string;
439
- pathname: string;
440
- params: AnyPathParams;
441
- parentMatch?: RouteMatch;
442
- childMatches: RouteMatch[];
443
- routeSearch: TRouteInfo['searchSchema'];
444
- search: TRouteInfo['fullSearchSchema'];
445
- status: 'idle' | 'loading' | 'success' | 'error';
446
- updatedAt?: number;
447
- error?: unknown;
448
- isInvalid: boolean;
449
- loaderData: TRouteInfo['loaderData'];
450
- routeLoaderData: TRouteInfo['routeLoaderData'];
451
- isFetching: boolean;
452
- isPending: boolean;
453
- __: {
454
- element?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
455
- errorElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
456
- catchElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
457
- pendingElement?: GetFrameworkGeneric<'Element', TRouteInfo['loaderData']>;
458
- loadPromise?: Promise<void>;
459
- loaderPromise?: Promise<void>;
460
- importPromise?: Promise<void>;
461
- elementsPromise?: Promise<void>;
462
- dataPromise?: Promise<void>;
463
- pendingTimeout?: Timeout;
464
- pendingMinTimeout?: Timeout;
465
- pendingMinPromise?: Promise<void>;
466
- onExit?: void | ((matchContext: {
467
- params: TRouteInfo['allParams'];
468
- search: TRouteInfo['fullSearchSchema'];
469
- }) => void);
470
- abortController: AbortController;
471
- latestId: string;
472
- setParentMatch: (parentMatch: RouteMatch) => void;
473
- addChildMatch: (childMatch: RouteMatch) => void;
474
- validate: () => void;
475
- startPending: () => void;
476
- cancelPending: () => void;
477
- notify: () => void;
478
- resolve: () => void;
479
- };
480
- cancel: () => void;
481
- load: () => Promise<void>;
482
- }
483
- export declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
484
- matchId: string;
485
- params: TRouteInfo['allParams'];
486
- pathname: string;
487
- }): RouteMatch<TAllRouteInfo, TRouteInfo>;
488
- export declare function matchPathname(currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
489
- export declare function warning(cond: any, message: string): cond is true;
490
- export declare function functionalUpdate<TResult>(updater?: Updater<TResult>, previous?: TResult): TResult | undefined;
491
- export declare function matchByPath(from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
492
- export declare function parsePathname(pathname?: string): Segment[];
493
- export declare function resolvePath(basepath: string, base: string, to: string): string;
494
- /**
495
- * This function returns `a` if `b` is deeply equal.
496
- * If not, it will replace any deeply equal children of `b` with those of `a`.
497
- * This can be used for structural sharing between JSON values for example.
498
- */
499
- export declare function replaceEqualDeep(prev: any, next: any): any;
500
- export declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
501
- export declare const defaultStringifySearch: (search: Record<string, any>) => string;
502
- export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
503
- export declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
504
- export declare function last<T>(arr: T[]): T | undefined;
@@ -1,2 +0,0 @@
1
- export declare function encode(obj: any, pfx?: string): string;
2
- export declare function decode(str: any): {};
package/src/package.json DELETED
@@ -1,48 +0,0 @@
1
- {
2
- "name": "@tanstack/router-core",
3
- "author": "Tanner Linsley",
4
- "version": "0.0.1-alpha.0",
5
- "license": "MIT",
6
- "repository": "tanstack/router",
7
- "homepage": "https://tanstack.com/router",
8
- "description": "",
9
- "publishConfig": {
10
- "registry": "https://registry.npmjs.org/"
11
- },
12
- "keywords": [
13
- "react",
14
- "location",
15
- "@tanstack/react-router",
16
- "router",
17
- "routing",
18
- "async",
19
- "async router",
20
- "typescript"
21
- ],
22
- "funding": {
23
- "type": "github",
24
- "url": "https://github.com/sponsors/tannerlinsley"
25
- },
26
- "module": "build/esm/index.js",
27
- "main": "build/cjs/index.js",
28
- "browser": "build/umd/index.production.js",
29
- "types": "build/types/index.d.ts",
30
- "engines": {
31
- "node": ">=12"
32
- },
33
- "files": [
34
- "build/**",
35
- "src"
36
- ],
37
- "peerDependencies": {
38
- "react": ">=16",
39
- "react-dom": ">=16"
40
- },
41
- "dependencies": {
42
- "@babel/runtime": "^7.16.7",
43
- "history": "^5.2.0"
44
- },
45
- "devDependencies": {
46
- "babel-plugin-transform-async-to-promises": "^0.8.18"
47
- }
48
- }