@tanstack/react-router 0.0.1-beta.9 → 1.0.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.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +128 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +233 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +172 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/awaited.js +43 -0
  11. package/build/cjs/awaited.js.map +1 -0
  12. package/build/cjs/defer.js +37 -0
  13. package/build/cjs/defer.js.map +1 -0
  14. package/build/cjs/fileRoute.js +27 -0
  15. package/build/cjs/fileRoute.js.map +1 -0
  16. package/build/cjs/index.js +130 -0
  17. package/build/cjs/index.js.map +1 -0
  18. package/build/cjs/lazyRouteComponent.js +54 -0
  19. package/build/cjs/lazyRouteComponent.js.map +1 -0
  20. package/build/cjs/link.js +223 -0
  21. package/build/cjs/link.js.map +1 -0
  22. package/build/cjs/path.js +214 -0
  23. package/build/cjs/path.js.map +1 -0
  24. package/build/cjs/qss.js +63 -0
  25. package/build/cjs/qss.js.map +1 -0
  26. package/build/cjs/redirects.js +28 -0
  27. package/build/cjs/redirects.js.map +1 -0
  28. package/build/cjs/route.js +191 -0
  29. package/build/cjs/route.js.map +1 -0
  30. package/build/cjs/router.js +1085 -0
  31. package/build/cjs/router.js.map +1 -0
  32. package/build/cjs/scroll-restoration.js +202 -0
  33. package/build/cjs/scroll-restoration.js.map +1 -0
  34. package/build/cjs/searchParams.js +81 -0
  35. package/build/cjs/searchParams.js.map +1 -0
  36. package/build/cjs/useBlocker.js +55 -0
  37. package/build/cjs/useBlocker.js.map +1 -0
  38. package/build/cjs/useNavigate.js +86 -0
  39. package/build/cjs/useNavigate.js.map +1 -0
  40. package/build/cjs/useParams.js +26 -0
  41. package/build/cjs/useParams.js.map +1 -0
  42. package/build/cjs/useSearch.js +25 -0
  43. package/build/cjs/useSearch.js.map +1 -0
  44. package/build/cjs/utils.js +241 -0
  45. package/build/cjs/utils.js.map +1 -0
  46. package/build/esm/index.js +2302 -2534
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +3498 -2694
  49. package/build/stats-react.json +1204 -44
  50. package/build/types/CatchBoundary.d.ts +36 -0
  51. package/build/types/Matches.d.ts +64 -0
  52. package/build/types/RouterProvider.d.ts +35 -0
  53. package/build/types/awaited.d.ts +9 -0
  54. package/build/types/defer.d.ts +19 -0
  55. package/build/types/fileRoute.d.ts +38 -0
  56. package/build/types/history.d.ts +7 -0
  57. package/build/types/index.d.ts +27 -74
  58. package/build/types/lazyRouteComponent.d.ts +2 -0
  59. package/build/types/link.d.ts +93 -0
  60. package/build/types/location.d.ts +12 -0
  61. package/build/types/path.d.ts +17 -0
  62. package/build/types/qss.d.ts +2 -0
  63. package/build/types/redirects.d.ts +11 -0
  64. package/build/types/route.d.ts +283 -0
  65. package/build/types/routeInfo.d.ts +31 -0
  66. package/build/types/router.d.ts +186 -0
  67. package/build/types/scroll-restoration.d.ts +18 -0
  68. package/build/types/searchParams.d.ts +7 -0
  69. package/build/types/useBlocker.d.ts +9 -0
  70. package/build/types/useNavigate.d.ts +19 -0
  71. package/build/types/useParams.d.ts +7 -0
  72. package/build/types/useSearch.d.ts +7 -0
  73. package/build/types/utils.d.ts +69 -0
  74. package/build/umd/index.development.js +2899 -2493
  75. package/build/umd/index.development.js.map +1 -1
  76. package/build/umd/index.production.js +4 -4
  77. package/build/umd/index.production.js.map +1 -1
  78. package/package.json +12 -10
  79. package/src/CatchBoundary.tsx +101 -0
  80. package/src/Matches.tsx +423 -0
  81. package/src/RouterProvider.tsx +254 -0
  82. package/src/awaited.tsx +40 -0
  83. package/src/defer.ts +55 -0
  84. package/src/fileRoute.ts +152 -0
  85. package/src/history.ts +8 -0
  86. package/src/index.tsx +28 -619
  87. package/src/lazyRouteComponent.tsx +33 -0
  88. package/src/link.tsx +603 -0
  89. package/src/location.ts +13 -0
  90. package/src/path.ts +261 -0
  91. package/src/qss.ts +53 -0
  92. package/src/redirects.ts +39 -0
  93. package/src/route.ts +882 -0
  94. package/src/routeInfo.ts +84 -0
  95. package/src/router.ts +1671 -0
  96. package/src/scroll-restoration.tsx +230 -0
  97. package/src/searchParams.ts +79 -0
  98. package/src/useBlocker.tsx +27 -0
  99. package/src/useNavigate.tsx +111 -0
  100. package/src/useParams.tsx +25 -0
  101. package/src/useSearch.tsx +25 -0
  102. package/src/utils.ts +360 -0
  103. package/build/cjs/react-router/src/index.js +0 -458
  104. package/build/cjs/react-router/src/index.js.map +0 -1
  105. package/build/cjs/router-core/build/esm/index.js +0 -2524
  106. package/build/cjs/router-core/build/esm/index.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ export declare function CatchBoundary(props: {
3
+ getResetKey: () => string;
4
+ children: any;
5
+ errorComponent?: any;
6
+ onCatch: (error: any) => void;
7
+ }): React.JSX.Element;
8
+ export declare class CatchBoundaryImpl extends React.Component<{
9
+ getResetKey: () => string;
10
+ children: (props: {
11
+ error: any;
12
+ reset: () => void;
13
+ }) => any;
14
+ onCatch?: (error: any) => void;
15
+ }> {
16
+ state: any;
17
+ static getDerivedStateFromProps(props: any): {
18
+ resetKey: any;
19
+ };
20
+ static getDerivedStateFromError(error: any): {
21
+ error: any;
22
+ };
23
+ componentDidUpdate(prevProps: Readonly<{
24
+ getResetKey: () => string;
25
+ children: (props: {
26
+ error: any;
27
+ reset: () => void;
28
+ }) => any;
29
+ onCatch?: ((error: any, info: any) => void) | undefined;
30
+ }>, prevState: any): void;
31
+ componentDidCatch(error: any): void;
32
+ render(): any;
33
+ }
34
+ export declare function ErrorComponent({ error }: {
35
+ error: any;
36
+ }): React.JSX.Element;
@@ -0,0 +1,64 @@
1
+ import * as React from 'react';
2
+ import { ResolveRelativePath, ToOptions } from './link';
3
+ import { AnyRoute, ReactNode } from './route';
4
+ import { FullSearchSchema, ParseRoute, RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
5
+ import { RegisteredRouter } from './router';
6
+ import { NoInfer, StrictOrFrom } from './utils';
7
+ export declare const matchContext: React.Context<string | undefined>;
8
+ export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id']> {
9
+ id: string;
10
+ routeId: TRouteId;
11
+ pathname: string;
12
+ params: RouteById<TRouteTree, TRouteId>['types']['allParams'];
13
+ status: 'pending' | 'success' | 'error';
14
+ isFetching: boolean;
15
+ showPending: boolean;
16
+ error: unknown;
17
+ paramsError: unknown;
18
+ searchError: unknown;
19
+ updatedAt: number;
20
+ loadPromise?: Promise<void>;
21
+ loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData'];
22
+ routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext'];
23
+ context: RouteById<TRouteTree, TRouteId>['types']['allContext'];
24
+ search: FullSearchSchema<TRouteTree> & RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'];
25
+ fetchCount: number;
26
+ abortController: AbortController;
27
+ cause: 'preload' | 'enter' | 'stay';
28
+ loaderDeps: RouteById<TRouteTree, TRouteId>['types']['loaderDeps'];
29
+ preload: boolean;
30
+ invalid: boolean;
31
+ }
32
+ export type AnyRouteMatch = RouteMatch<any, any>;
33
+ export declare function Matches(): React.JSX.Element;
34
+ export declare function Match({ matchId }: {
35
+ matchId: string;
36
+ }): React.JSX.Element;
37
+ export declare const Outlet: React.NamedExoticComponent<object>;
38
+ export interface MatchRouteOptions {
39
+ pending?: boolean;
40
+ caseSensitive?: boolean;
41
+ includeSearch?: boolean;
42
+ fuzzy?: boolean;
43
+ }
44
+ export type UseMatchRouteOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToOptions<AnyRoute, TFrom, TTo, TMaskFrom, TMaskTo> & MatchRouteOptions;
45
+ export declare function useMatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TMaskFrom extends RoutePaths<TRouteTree> = "/", TMaskTo extends string = "", TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>>(opts: UseMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
46
+ export type MakeMatchRouteOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & MatchRouteOptions & {
47
+ children?: ((params?: RouteByPath<TRouteTree, ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
48
+ };
49
+ export declare function MatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): any;
50
+ export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatchState = RouteMatch<TRouteTree, TFrom>, TSelected = TRouteMatchState>(opts: StrictOrFrom<TFrom> & {
51
+ select?: (match: TRouteMatchState) => TSelected;
52
+ }): TStrict extends true ? TSelected : TSelected | undefined;
53
+ export declare function useMatches<T = RouteMatch[]>(opts?: {
54
+ select?: (matches: RouteMatch[]) => T;
55
+ }): T;
56
+ export declare function useParentMatches<T = RouteMatch[]>(opts?: {
57
+ select?: (matches: RouteMatch[]) => T;
58
+ }): T;
59
+ 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> & {
60
+ select?: (match: TRouteMatch) => TSelected;
61
+ }): TStrict extends true ? TSelected : TSelected | undefined;
62
+ 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> & {
63
+ select?: (match: TRouteMatch) => TSelected;
64
+ }): TStrict extends true ? TSelected : TSelected | undefined;
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ import { NavigateOptions, ResolveRelativePath, ToOptions } from './link';
3
+ import { ParsedLocation } from './location';
4
+ import { AnyRoute } from './route';
5
+ import { RouteById, RoutePaths } from './routeInfo';
6
+ import { RegisteredRouter, Router, RouterOptions, RouterState } from './router';
7
+ import { NoInfer } from './utils';
8
+ import { MatchRouteOptions } from './Matches';
9
+ import { RouteMatch } from './Matches';
10
+ export interface CommitLocationOptions {
11
+ replace?: boolean;
12
+ resetScroll?: boolean;
13
+ startTransition?: boolean;
14
+ }
15
+ export interface MatchLocation {
16
+ to?: string | number | null;
17
+ fuzzy?: boolean;
18
+ caseSensitive?: boolean;
19
+ from?: string;
20
+ }
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
+ 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: ToOptions<TRouteTree>) => ParsedLocation;
24
+ export type InjectedHtmlEntry = string | (() => Promise<string> | string);
25
+ export declare let routerContext: React.Context<Router<any, Record<string, any>>>;
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;
27
+ export declare function getRouteMatch<TRouteTree extends AnyRoute>(state: RouterState<TRouteTree>, id: string): undefined | RouteMatch<TRouteTree>;
28
+ export declare function useRouterState<TSelected = RouterState<RegisteredRouter['routeTree']>>(opts?: {
29
+ select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected;
30
+ }): TSelected;
31
+ export type RouterProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TDehydrated extends Record<string, any> = Record<string, any>> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {
32
+ router: Router<TRouteTree>;
33
+ context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>;
34
+ };
35
+ export declare function useRouter<TRouteTree extends AnyRoute = RegisteredRouter['routeTree']>(): Router<TRouteTree>;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { DeferredPromise } from './defer';
3
+ export type AwaitOptions<T> = {
4
+ promise: DeferredPromise<T>;
5
+ };
6
+ export declare function useAwaited<T>({ promise }: AwaitOptions<T>): [T];
7
+ export declare function Await<T>(props: AwaitOptions<T> & {
8
+ children: (result: T) => JSX.Element;
9
+ }): JSX.Element;
@@ -0,0 +1,19 @@
1
+ export type DeferredPromiseState<T> = {
2
+ uid: string;
3
+ } & ({
4
+ status: 'pending';
5
+ data?: T;
6
+ error?: unknown;
7
+ } | {
8
+ status: 'success';
9
+ data: T;
10
+ } | {
11
+ status: 'error';
12
+ data?: T;
13
+ error: unknown;
14
+ });
15
+ export type DeferredPromise<T> = Promise<T> & {
16
+ __deferredState: DeferredPromiseState<T>;
17
+ };
18
+ export declare function defer<T>(_promise: Promise<T>): DeferredPromise<T>;
19
+ export declare function isDehydratedDeferred(obj: any): boolean;
@@ -0,0 +1,38 @@
1
+ import { ParsePathParams } from './link';
2
+ import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints } from './route';
3
+ import { Assign, Expand, IsAny } from './utils';
4
+ export interface FileRoutesByPath {
5
+ }
6
+ type Replace<S extends string, From extends string, To extends string> = S extends `${infer Start}${From}${infer Rest}` ? `${Start}${To}${Replace<Rest, From, To>}` : S;
7
+ export type TrimLeft<T extends string, S extends string> = T extends `${S}${infer U}` ? U : T;
8
+ export type TrimRight<T extends string, S extends string> = T extends `${infer U}${S}` ? U : T;
9
+ export type Trim<T extends string, S extends string> = TrimLeft<TrimRight<T, S>, S>;
10
+ export type RemoveUnderScores<T extends string> = Replace<Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>, '/_', '/'>;
11
+ export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : Replace<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
12
+ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? string : ResolveFilePath<TParentRoute, TFilePath>;
13
+ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
14
+ path: TFilePath;
15
+ constructor(path: TFilePath);
16
+ createRoute: <TSearchSchema extends import("./route").AnySearchSchema = {}, TFullSearchSchema extends import("./route").AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContext extends RouteContext = RouteContext, TContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & {
17
+ meta?: import("./route").RouteMeta | undefined;
18
+ } & {
19
+ caseSensitive?: boolean | undefined;
20
+ wrapInSuspense?: boolean | undefined;
21
+ component?: import("./route").RouteComponent<any> | undefined;
22
+ errorComponent?: false | import("./route").ErrorRouteComponent | null | undefined;
23
+ pendingComponent?: import("./route").RouteComponent<any> | undefined;
24
+ pendingMs?: number | undefined;
25
+ pendingMinMs?: number | undefined;
26
+ staleTime?: number | undefined;
27
+ gcTime?: number | undefined;
28
+ preloadStaleTime?: number | undefined;
29
+ preloadGcTime?: number | undefined;
30
+ preSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
31
+ postSearchFilters?: import("./route").SearchFilter<TFullSearchSchema, TFullSearchSchema>[] | undefined;
32
+ onError?: ((err: any) => void) | undefined;
33
+ onEnter?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
34
+ onStay?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
35
+ onLeave?: ((match: import("./Matches").AnyRouteMatch) => void) | undefined;
36
+ }) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
37
+ }
38
+ export {};
@@ -0,0 +1,7 @@
1
+ import { HistoryLocation } from '@tanstack/history';
2
+ declare module '@tanstack/history' {
3
+ interface HistoryState {
4
+ __tempLocation?: HistoryLocation;
5
+ __tempKey?: string;
6
+ }
7
+ }
@@ -1,74 +1,27 @@
1
- /**
2
- * react-router
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 * as React from 'react';
12
- import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RouterState, RouteMatch, ToOptions, MatchRouteOptions, RouteInfoByPath, ResolveRelativePath, NoInfer, DefaultAllRouteInfo, AnyRouteInfo, RouteInfo, CheckId, ToIdOption, ValidFromPath, LinkOptions, RouterOptions, Router } from '@tanstack/router-core';
13
- export * from '@tanstack/router-core';
14
-
15
- declare module '@tanstack/router-core' {
16
- interface FrameworkGenerics {
17
- Element: React.ReactNode;
18
- SyncOrAsyncElement: React.ReactNode | (() => Promise<any>);
19
- }
20
- interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
21
- useState: () => RouterState;
22
- useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
23
- useMatch: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => RouteMatch<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
24
- linkProps: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, '/', TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
25
- Link: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, '/', TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
26
- children?: React.ReactNode | ((state: {
27
- isActive: boolean;
28
- }) => React.ReactNode);
29
- }) => JSX.Element;
30
- MatchRoute: <TTo extends string = '.'>(props: ToOptions<TAllRouteInfo, '/', TTo> & MatchRouteOptions & {
31
- children?: React.ReactNode | ((params: RouteInfoByPath<TAllRouteInfo, ResolveRelativePath<'/', NoInfer<TTo>>>['allParams']) => React.ReactNode);
32
- }) => JSX.Element;
33
- }
34
- interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
35
- useRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], NoInfer<TTo>>>(routeId: CheckId<TAllRouteInfo, TResolved, ToIdOption<TAllRouteInfo, TRouteInfo['id'], TTo>>) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TResolved]>;
36
- linkProps: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
37
- Link: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
38
- children?: React.ReactNode | ((state: {
39
- isActive: boolean;
40
- }) => React.ReactNode);
41
- }) => JSX.Element;
42
- MatchRoute: <TTo extends string = '.'>(props: ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & MatchRouteOptions & {
43
- children?: React.ReactNode | ((params: RouteInfoByPath<TAllRouteInfo, ResolveRelativePath<TRouteInfo['fullPath'], NoInfer<TTo>>>['allParams']) => React.ReactNode);
44
- }) => JSX.Element;
45
- }
46
- }
47
- declare type LinkPropsOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = LinkOptions<TAllRouteInfo, TFrom, TTo> & {
48
- activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
49
- inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
50
- };
51
- declare type PromptProps = {
52
- message: string;
53
- when?: boolean | any;
54
- children?: React.ReactNode;
55
- };
56
- declare type MatchesProviderProps = {
57
- value: RouteMatch[];
58
- children: React.ReactNode;
59
- };
60
- declare function MatchesProvider(props: MatchesProviderProps): JSX.Element;
61
- declare function createReactRouter<TRouteConfig extends AnyRouteConfig = RouteConfig>(opts: RouterOptions<TRouteConfig>): Router<TRouteConfig>;
62
- declare type RouterProps<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = RouterOptions<TRouteConfig> & {
63
- router: Router<TRouteConfig, TAllRouteInfo>;
64
- children?: React.ReactNode;
65
- };
66
- declare function RouterProvider<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo>({ children, router, ...rest }: RouterProps<TRouteConfig, TAllRouteInfo>): JSX.Element;
67
- declare function Outlet(): JSX.Element | null;
68
- declare function DefaultErrorBoundary({ error }: {
69
- error: any;
70
- }): JSX.Element;
71
- declare function usePrompt(message: string, when: boolean | any): void;
72
- declare function Prompt({ message, when, children }: PromptProps): React.ReactNode;
73
-
74
- export { DefaultErrorBoundary, MatchesProvider, MatchesProviderProps, Outlet, Prompt, PromptProps, RouterProps, RouterProvider, createReactRouter, usePrompt };
1
+ export * from '@tanstack/history';
2
+ export { default as invariant } from 'tiny-invariant';
3
+ export { default as warning } from 'tiny-warning';
4
+ export * from './awaited';
5
+ export * from './defer';
6
+ export * from './CatchBoundary';
7
+ export * from './fileRoute';
8
+ export * from './history';
9
+ export * from './index';
10
+ export * from './lazyRouteComponent';
11
+ export * from './link';
12
+ export * from './location';
13
+ export * from './Matches';
14
+ export * from './path';
15
+ export * from './qss';
16
+ export * from './redirects';
17
+ export * from './route';
18
+ export * from './routeInfo';
19
+ export * from './router';
20
+ export * from './RouterProvider';
21
+ export * from './scroll-restoration';
22
+ export * from './searchParams';
23
+ export * from './useBlocker';
24
+ export * from './useNavigate';
25
+ export * from './useParams';
26
+ export * from './useSearch';
27
+ export * from './utils';
@@ -0,0 +1,2 @@
1
+ import { AsyncRouteComponent } from './route';
2
+ 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;
@@ -0,0 +1,93 @@
1
+ import * as React from 'react';
2
+ import { Trim } from './fileRoute';
3
+ import { AnyRoute, ReactNode } from './route';
4
+ import { AllParams, FullSearchSchema, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
5
+ import { RegisteredRouter } from './router';
6
+ import { LinkProps, UseLinkPropsOptions } from './useNavigate';
7
+ import { Expand, NoInfer, NonNullableUpdater, PickRequired, UnionToIntersection, Updater } from './utils';
8
+ import { HistoryState } from '@tanstack/history';
9
+ export 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;
10
+ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
11
+ export type ParsePathParams<T extends string> = keyof {
12
+ [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K;
13
+ };
14
+ export type Join<T, Delimiter extends string = '/'> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}${Delimiter}${Join<Tail>}`> : never;
15
+ export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never;
16
+ export type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
17
+ ...Split<ResolveRelativePath<TFrom, TTo>, false>,
18
+ ...infer TToRest
19
+ ] ? `${CleanPath<Join<[
20
+ ...Split<TTo, false>,
21
+ ...(TToRest | (Split<ResolveRelativePath<TFrom, TTo>, false>['length'] extends 1 ? never : ['../']))
22
+ ]>>}` : never : TTo extends `./${infer RestTTo}` ? SplitPaths extends [
23
+ ...Split<TFrom, false>,
24
+ ...Split<RestTTo, false>,
25
+ ...infer RestPath
26
+ ] ? `${TTo}${Join<RestPath>}` : never : (TFrom extends `/` ? never : SplitPaths extends [...Split<TFrom, false>, ...infer RestPath] ? Join<RestPath> extends {
27
+ length: 0;
28
+ } ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
29
+ export type NavigateOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
30
+ replace?: boolean;
31
+ resetScroll?: boolean;
32
+ startTransition?: boolean;
33
+ };
34
+ export type ToOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TFrom, TTo> & {
35
+ mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>;
36
+ };
37
+ export type ToMaskOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
38
+ unmaskOnReload?: boolean;
39
+ };
40
+ export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
41
+ to?: ToPathOption<TRouteTree, TFrom, TTo>;
42
+ hash?: true | Updater<string>;
43
+ state?: true | NonNullableUpdater<HistoryState>;
44
+ from?: TFrom;
45
+ } & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TResolved>;
46
+ export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>, TFromSearchEnsured = '/' extends TFrom ? FullSearchSchema<TRouteTree> : Expand<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']>>, TFromSearchOptional = Omit<FullSearchSchema<TRouteTree>, keyof TFromSearchEnsured>, TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>, TToSearch = '' extends TTo ? FullSearchSchema<TRouteTree> : Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>> = keyof PickRequired<TToSearch> extends never ? {
47
+ search?: true | SearchReducer<TFromSearch, TToSearch>;
48
+ } : {
49
+ search: TFromSearchEnsured extends PickRequired<TToSearch> ? true | SearchReducer<TFromSearch, TToSearch> : SearchReducer<TFromSearch, TToSearch>;
50
+ };
51
+ type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
52
+ export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TFromParamsEnsured = Expand<UnionToIntersection<PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>>>, TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>, TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>, TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>> = never extends TToParams ? {
53
+ params?: true | ParamsReducer<Partial<TFromParams>, Partial<TFromParams>>;
54
+ } : keyof PickRequired<TToParams> extends never ? {
55
+ params?: true | ParamsReducer<TFromParams, TToParams>;
56
+ } : {
57
+ params: TFromParamsEnsured extends PickRequired<TToParams> ? true | ParamsReducer<TFromParams, TToParams> : ParamsReducer<TFromParams, TToParams>;
58
+ };
59
+ type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
60
+ export type ToPathOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RoutePaths<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
61
+ export type ToIdOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RouteIds<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
62
+ export interface ActiveOptions {
63
+ exact?: boolean;
64
+ includeHash?: boolean;
65
+ includeSearch?: boolean;
66
+ }
67
+ export type LinkOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
68
+ target?: HTMLAnchorElement['target'];
69
+ activeOptions?: ActiveOptions;
70
+ preload?: false | 'intent';
71
+ preloadDelay?: number;
72
+ disabled?: boolean;
73
+ };
74
+ export type CheckRelativePath<TRouteTree extends AnyRoute, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree> ? {} : {
75
+ Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
76
+ 'Valid Route Paths': RoutePaths<TRouteTree>;
77
+ } : {} : {};
78
+ export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<TPath, RoutePaths<TRouteTree>> extends never ? TPass : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>;
79
+ export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
80
+ to: RoutePaths<TRouteTree>;
81
+ };
82
+ export type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<TPath, RouteIds<TRouteTree>> extends never ? TPass : CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>;
83
+ export type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {
84
+ Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
85
+ 'Valid Route IDs': RouteIds<TRouteTree>;
86
+ };
87
+ export type ResolveRelativePath<TFrom, TTo = '.'> = 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] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
88
+ export declare function useLinkProps<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(options: UseLinkPropsOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
89
+ export interface LinkComponent<TProps extends Record<string, any> = {}> {
90
+ <TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: LinkProps<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & TProps & React.RefAttributes<HTMLAnchorElement>): ReactNode;
91
+ }
92
+ export declare const Link: LinkComponent;
93
+ export {};
@@ -0,0 +1,12 @@
1
+ import { HistoryState } from '@tanstack/history';
2
+ import { AnySearchSchema } from './route';
3
+ export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
4
+ href: string;
5
+ pathname: string;
6
+ search: TSearchObj;
7
+ searchStr: string;
8
+ state: HistoryState;
9
+ hash: string;
10
+ maskedLocation?: ParsedLocation<TSearchObj>;
11
+ unmaskOnReload?: boolean;
12
+ }
@@ -0,0 +1,17 @@
1
+ import { MatchLocation } from './RouterProvider';
2
+ import { AnyPathParams } from './route';
3
+ export interface Segment {
4
+ type: 'pathname' | 'param' | 'wildcard';
5
+ value: string;
6
+ }
7
+ export declare function joinPaths(paths: (string | undefined)[]): string;
8
+ export declare function cleanPath(path: string): string;
9
+ export declare function trimPathLeft(path: string): string;
10
+ export declare function trimPathRight(path: string): string;
11
+ export declare function trimPath(path: string): string;
12
+ export declare function resolvePath(basepath: string, base: string, to: string): string;
13
+ export declare function parsePathname(pathname?: string): Segment[];
14
+ export declare function interpolatePath(path: string | undefined, params: any, leaveWildcards?: boolean): string;
15
+ export declare function matchPathname(basepath: string, currentPathname: string, matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>): AnyPathParams | undefined;
16
+ export declare function removeBasepath(basepath: string, pathname: string): string;
17
+ export declare function matchByPath(basepath: string, from: string, matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>): Record<string, string> | undefined;
@@ -0,0 +1,2 @@
1
+ export declare function encode(obj: any, pfx?: string): string;
2
+ export declare function decode(str: any): {};
@@ -0,0 +1,11 @@
1
+ import { NavigateOptions } from './link';
2
+ import { AnyRoute } from './route';
3
+ import { RoutePaths } from './routeInfo';
4
+ import { RegisteredRouter } from './router';
5
+ export type AnyRedirect = Redirect<any, any, any, any, any>;
6
+ export type Redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''> = {
7
+ code?: number;
8
+ throw?: any;
9
+ } & NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>;
10
+ export declare function redirect<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>(opts: Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>;
11
+ export declare function isRedirect(obj: any): obj is AnyRedirect;