@tanstack/react-router 1.114.23 → 1.114.24
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/dist/cjs/route.cjs +42 -90
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +12 -46
- package/dist/esm/route.d.ts +12 -46
- package/dist/esm/route.js +43 -91
- package/dist/esm/route.js.map +1 -1
- package/package.json +2 -2
- package/src/route.ts +87 -335
package/dist/cjs/route.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const invariant = require("tiny-invariant");
|
|
4
3
|
const routerCore = require("@tanstack/router-core");
|
|
5
4
|
const useLoaderData = require("./useLoaderData.cjs");
|
|
6
5
|
const useLoaderDeps = require("./useLoaderDeps.cjs");
|
|
@@ -12,11 +11,12 @@ const useRouter = require("./useRouter.cjs");
|
|
|
12
11
|
function getRouteApi(id) {
|
|
13
12
|
return new RouteApi({ id });
|
|
14
13
|
}
|
|
15
|
-
class RouteApi {
|
|
14
|
+
class RouteApi extends routerCore.BaseRouteApi {
|
|
16
15
|
/**
|
|
17
16
|
* @deprecated Use the `getRouteApi` function instead.
|
|
18
17
|
*/
|
|
19
18
|
constructor({ id }) {
|
|
19
|
+
super({ id });
|
|
20
20
|
this.useMatch = (opts) => {
|
|
21
21
|
return useMatch.useMatch({
|
|
22
22
|
select: opts == null ? void 0 : opts.select,
|
|
@@ -57,77 +57,14 @@ class RouteApi {
|
|
|
57
57
|
this.notFound = (opts) => {
|
|
58
58
|
return routerCore.notFound({ routeId: this.id, ...opts });
|
|
59
59
|
};
|
|
60
|
-
this.id = id;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
class Route {
|
|
62
|
+
class Route extends routerCore.BaseRoute {
|
|
64
63
|
/**
|
|
65
64
|
* @deprecated Use the `createRoute` function instead.
|
|
66
65
|
*/
|
|
67
66
|
constructor(options) {
|
|
68
|
-
|
|
69
|
-
var _a, _b;
|
|
70
|
-
this.originalIndex = opts.originalIndex;
|
|
71
|
-
const options2 = this.options;
|
|
72
|
-
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
|
|
73
|
-
this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a);
|
|
74
|
-
if (isRoot) {
|
|
75
|
-
this._path = routerCore.rootRouteId;
|
|
76
|
-
} else {
|
|
77
|
-
invariant(
|
|
78
|
-
this.parentRoute,
|
|
79
|
-
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
let path = isRoot ? routerCore.rootRouteId : options2.path;
|
|
83
|
-
if (path && path !== "/") {
|
|
84
|
-
path = routerCore.trimPathLeft(path);
|
|
85
|
-
}
|
|
86
|
-
const customId = (options2 == null ? void 0 : options2.id) || path;
|
|
87
|
-
let id = isRoot ? routerCore.rootRouteId : routerCore.joinPaths([
|
|
88
|
-
this.parentRoute.id === routerCore.rootRouteId ? "" : this.parentRoute.id,
|
|
89
|
-
customId
|
|
90
|
-
]);
|
|
91
|
-
if (path === routerCore.rootRouteId) {
|
|
92
|
-
path = "/";
|
|
93
|
-
}
|
|
94
|
-
if (id !== routerCore.rootRouteId) {
|
|
95
|
-
id = routerCore.joinPaths(["/", id]);
|
|
96
|
-
}
|
|
97
|
-
const fullPath = id === routerCore.rootRouteId ? "/" : routerCore.joinPaths([this.parentRoute.fullPath, path]);
|
|
98
|
-
this._path = path;
|
|
99
|
-
this._id = id;
|
|
100
|
-
this._fullPath = fullPath;
|
|
101
|
-
this._to = fullPath;
|
|
102
|
-
this._ssr = (options2 == null ? void 0 : options2.ssr) ?? opts.defaultSsr ?? true;
|
|
103
|
-
};
|
|
104
|
-
this.addChildren = (children) => {
|
|
105
|
-
return this._addFileChildren(children);
|
|
106
|
-
};
|
|
107
|
-
this._addFileChildren = (children) => {
|
|
108
|
-
if (Array.isArray(children)) {
|
|
109
|
-
this.children = children;
|
|
110
|
-
}
|
|
111
|
-
if (typeof children === "object" && children !== null) {
|
|
112
|
-
this.children = Object.values(children);
|
|
113
|
-
}
|
|
114
|
-
return this;
|
|
115
|
-
};
|
|
116
|
-
this._addFileTypes = () => {
|
|
117
|
-
return this;
|
|
118
|
-
};
|
|
119
|
-
this.updateLoader = (options2) => {
|
|
120
|
-
Object.assign(this.options, options2);
|
|
121
|
-
return this;
|
|
122
|
-
};
|
|
123
|
-
this.update = (options2) => {
|
|
124
|
-
Object.assign(this.options, options2);
|
|
125
|
-
return this;
|
|
126
|
-
};
|
|
127
|
-
this.lazy = (lazyFn) => {
|
|
128
|
-
this.lazyFn = lazyFn;
|
|
129
|
-
return this;
|
|
130
|
-
};
|
|
67
|
+
super(options);
|
|
131
68
|
this.useMatch = (opts) => {
|
|
132
69
|
return useMatch.useMatch({
|
|
133
70
|
select: opts == null ? void 0 : opts.select,
|
|
@@ -165,28 +102,6 @@ class Route {
|
|
|
165
102
|
this.useNavigate = () => {
|
|
166
103
|
return useNavigate.useNavigate({ from: this.fullPath });
|
|
167
104
|
};
|
|
168
|
-
this.options = options || {};
|
|
169
|
-
this.isRoot = !(options == null ? void 0 : options.getParentRoute);
|
|
170
|
-
invariant(
|
|
171
|
-
!((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)),
|
|
172
|
-
`Route cannot have both an 'id' and a 'path' option.`
|
|
173
|
-
);
|
|
174
|
-
this.$$typeof = Symbol.for("react.memo");
|
|
175
|
-
}
|
|
176
|
-
get to() {
|
|
177
|
-
return this._to;
|
|
178
|
-
}
|
|
179
|
-
get id() {
|
|
180
|
-
return this._id;
|
|
181
|
-
}
|
|
182
|
-
get path() {
|
|
183
|
-
return this._path;
|
|
184
|
-
}
|
|
185
|
-
get fullPath() {
|
|
186
|
-
return this._fullPath;
|
|
187
|
-
}
|
|
188
|
-
get ssr() {
|
|
189
|
-
return this._ssr;
|
|
190
105
|
}
|
|
191
106
|
}
|
|
192
107
|
function createRoute(options) {
|
|
@@ -198,12 +113,49 @@ function createRootRouteWithContext() {
|
|
|
198
113
|
};
|
|
199
114
|
}
|
|
200
115
|
const rootRouteWithContext = createRootRouteWithContext;
|
|
201
|
-
class RootRoute extends
|
|
116
|
+
class RootRoute extends routerCore.BaseRootRoute {
|
|
202
117
|
/**
|
|
203
118
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
204
119
|
*/
|
|
205
120
|
constructor(options) {
|
|
206
121
|
super(options);
|
|
122
|
+
this.useMatch = (opts) => {
|
|
123
|
+
return useMatch.useMatch({
|
|
124
|
+
select: opts == null ? void 0 : opts.select,
|
|
125
|
+
from: this.id,
|
|
126
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
this.useRouteContext = (opts) => {
|
|
130
|
+
return useMatch.useMatch({
|
|
131
|
+
...opts,
|
|
132
|
+
from: this.id,
|
|
133
|
+
select: (d) => (opts == null ? void 0 : opts.select) ? opts.select(d.context) : d.context
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
this.useSearch = (opts) => {
|
|
137
|
+
return useSearch.useSearch({
|
|
138
|
+
select: opts == null ? void 0 : opts.select,
|
|
139
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing,
|
|
140
|
+
from: this.id
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
this.useParams = (opts) => {
|
|
144
|
+
return useParams.useParams({
|
|
145
|
+
select: opts == null ? void 0 : opts.select,
|
|
146
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing,
|
|
147
|
+
from: this.id
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
this.useLoaderDeps = (opts) => {
|
|
151
|
+
return useLoaderDeps.useLoaderDeps({ ...opts, from: this.id });
|
|
152
|
+
};
|
|
153
|
+
this.useLoaderData = (opts) => {
|
|
154
|
+
return useLoaderData.useLoaderData({ ...opts, from: this.id });
|
|
155
|
+
};
|
|
156
|
+
this.useNavigate = () => {
|
|
157
|
+
return useNavigate.useNavigate({ from: this.fullPath });
|
|
158
|
+
};
|
|
207
159
|
}
|
|
208
160
|
}
|
|
209
161
|
function createRootRoute(options) {
|
package/dist/cjs/route.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.cjs","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport {\n joinPaths,\n notFound,\n rootRouteId,\n trimPathLeft,\n} from '@tanstack/router-core'\nimport { useLoaderData } from './useLoaderData'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { useNavigate } from './useNavigate'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n Constrain,\n ConstrainLiteral,\n LazyRoute as CoreLazyRoute,\n Route as CoreRoute,\n ErrorComponentProps,\n NotFoundError,\n NotFoundRouteProps,\n RegisteredRouter,\n ResolveFullPath,\n ResolveId,\n ResolveParams,\n RootRouteId,\n RootRouteOptions,\n RouteAddChildrenFn,\n RouteAddFileChildrenFn,\n RouteAddFileTypesFn,\n RouteConstraints,\n RouteIds,\n RouteLazyFn,\n RouteLoaderFn,\n RouteMask,\n RouteOptions,\n RoutePathOptionsIntersection,\n RouteTypes,\n RouteTypesById,\n Router,\n ToMaskOptions,\n TrimPathRight,\n UpdatableRouteOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseSearchRoute } from './useSearch'\nimport type * as React from 'react'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\ndeclare module '@tanstack/router-core' {\n export interface UpdatableRouteOptionsExtensions {\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n }\n\n export interface RouteExtensions<\n TId extends string,\n TFullPath extends string,\n > {\n useMatch: UseMatchRoute<TId>\n useRouteContext: UseRouteContextRoute<TId>\n useSearch: UseSearchRoute<TId>\n useParams: UseParamsRoute<TId>\n useLoaderDeps: UseLoaderDepsRoute<TId>\n useLoaderData: UseLoaderDataRoute<TId>\n useNavigate: () => UseNavigateResult<TFullPath>\n }\n}\n\nexport function getRouteApi<\n const TId,\n TRouter extends AnyRouter = RegisteredRouter,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return new RouteApi<TId, TRouter>({ id })\n}\n\nexport class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {\n id: TId\n\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts) => {\n return useMatch({\n from: this.id as any,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<\n RouteTypesById<TRouter, TId>['fullPath']\n > => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.id as string].fullPath })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> implements\n CoreRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n{\n isRoot: TParentRoute extends AnyRoute ? true : false\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n\n // The following properties are set up in this.init()\n parentRoute!: TParentRoute\n private _id!: TId\n private _path!: TPath\n private _fullPath!: TFullPath\n private _to!: TrimPathRight<TFullPath>\n private _ssr!: boolean\n\n public get to() {\n /* invariant(\n this._to,\n `trying to access property 'to' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._to\n }\n\n public get id() {\n /* invariant(\n this._id,\n `trying to access property 'id' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._id\n }\n\n public get path() {\n /* invariant(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.isRoot || this._id || this._path,\n `trying to access property 'path' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._path\n }\n\n public get fullPath() {\n /* invariant(\n this._fullPath,\n `trying to access property 'fullPath' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._fullPath\n }\n\n public get ssr() {\n return this._ssr\n }\n\n // Optional\n children?: TChildren\n originalIndex?: number\n rank!: number\n lazyFn?: () => Promise<CoreLazyRoute>\n _lazyPromise?: Promise<void>\n _componentsPromise?: Promise<Array<void>>\n\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) {\n this.options = (options as any) || {}\n\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: RouteTypes<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n\n init = (opts: { originalIndex: number; defaultSsr?: boolean }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.parentRoute = this.options.getParentRoute?.()\n\n if (isRoot) {\n this._path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this._path = path as TPath\n this._id = id as TId\n // this.customId = customId as TCustomId\n this._fullPath = fullPath as TFullPath\n this._to = fullPath as TrimPathRight<TFullPath>\n this._ssr = options?.ssr ?? opts.defaultSsr ?? true\n }\n\n addChildren: RouteAddChildrenFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes\n > = (children) => {\n return this._addFileChildren(children) as any\n }\n\n _addFileChildren: RouteAddFileChildrenFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes\n > = (children) => {\n if (Array.isArray(children)) {\n this.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n this.children = Object.values(children) as TChildren\n }\n\n return this as any\n }\n\n _addFileTypes: RouteAddFileTypesFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n > = () => {\n return this as any\n }\n\n updateLoader = <TNewLoaderFn>(options: {\n loader: Constrain<\n TNewLoaderFn,\n RouteLoaderFn<\n TParentRoute,\n TCustomId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n }) => {\n Object.assign(this.options, options)\n return this as unknown as Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TNewLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy: RouteLazyFn<this> = (lazyFn) => {\n this.lazyFn = lazyFn\n return this\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts?) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n): CoreRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n unknown\n> {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) {\n super(options as any)\n }\n}\n\nexport function createRootRoute<\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n) {\n return new RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options)\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends string,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never', boolean>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TRouterContext = AnyContext,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n string,\n string,\n TSearchValidator,\n {},\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'path'\n | 'id'\n | 'params'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["useMatch","useSearch","useParams","useLoaderDeps","useLoaderData","useRouter","useNavigate","notFound","options","rootRouteId","trimPathLeft","joinPaths"],"mappings":";;;;;;;;;;;AA+EO,SAAS,YAGd,IAA2D;AAC3D,SAAO,IAAI,SAAuB,EAAE,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ent":["import {\n BaseRootRoute,\n BaseRoute,\n BaseRouteApi,\n notFound,\n} from '@tanstack/router-core'\nimport { useLoaderData } from './useLoaderData'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { useNavigate } from './useNavigate'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n ConstrainLiteral,\n ErrorComponentProps,\n NotFoundError,\n NotFoundRouteProps,\n RegisteredRouter,\n ResolveFullPath,\n ResolveId,\n ResolveParams,\n RootRouteId,\n RootRouteOptions,\n RouteConstraints,\n RouteIds,\n RouteMask,\n RouteOptions,\n RouteTypesById,\n Router,\n ToMaskOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseSearchRoute } from './useSearch'\nimport type * as React from 'react'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\ndeclare module '@tanstack/router-core' {\n export interface UpdatableRouteOptionsExtensions {\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n }\n\n export interface RouteExtensions<\n TId extends string,\n TFullPath extends string,\n > {\n useMatch: UseMatchRoute<TId>\n useRouteContext: UseRouteContextRoute<TId>\n useSearch: UseSearchRoute<TId>\n useParams: UseParamsRoute<TId>\n useLoaderDeps: UseLoaderDepsRoute<TId>\n useLoaderData: UseLoaderDataRoute<TId>\n useNavigate: () => UseNavigateResult<TFullPath>\n }\n}\n\nexport function getRouteApi<\n const TId,\n TRouter extends AnyRouter = RegisteredRouter,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return new RouteApi<TId, TRouter>({ id })\n}\n\nexport class RouteApi<\n TId,\n TRouter extends AnyRouter = RegisteredRouter,\n> extends BaseRouteApi<TId, TRouter> {\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n super({ id })\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts) => {\n return useMatch({\n from: this.id as any,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<\n RouteTypesById<TRouter, TId>['fullPath']\n > => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.id as string].fullPath })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends BaseRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n> {\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) {\n super(options)\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts?) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends BaseRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) {\n super(options)\n }\n\n useMatch: UseMatchRoute<RootRouteId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<RootRouteId> = (opts) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<RootRouteId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<RootRouteId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<RootRouteId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<RootRouteId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<'/'> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRootRoute<\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n): RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n unknown,\n unknown\n> {\n return new RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options)\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends string,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never', boolean>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TRouterContext = AnyContext,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n string,\n string,\n TSearchValidator,\n {},\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'path'\n | 'id'\n | 'params'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["BaseRouteApi","useMatch","useSearch","useParams","useLoaderDeps","useLoaderData","useRouter","useNavigate","notFound","BaseRoute","BaseRootRoute"],"mappings":";;;;;;;;;;AAkEO,SAAS,YAGd,IAA2D;AAC3D,SAAO,IAAI,SAAuB,EAAE,IAAI;AAC1C;AAEO,MAAM,iBAGHA,WAAAA,aAA2B;AAAA;AAAA;AAAA;AAAA,EAInC,YAAY,EAAE,MAAmB;AACzB,UAAA,EAAE,IAAI;AAGd,SAAA,WAA+B,CAAC,SAAS;AACvC,aAAOC,kBAAS;AAAA,QACd,QAAQ,6BAAM;AAAA,QACd,MAAM,KAAK;AAAA,QACX,mBAAmB,6BAAM;AAAA,MAAA,CACnB;AAAA,IACV;AAEA,SAAA,kBAA6C,CAAC,SAAS;AACrD,aAAOA,kBAAS;AAAA,QACd,MAAM,KAAK;AAAA,QACX,QAAQ,CAAC,OAAO,6BAAM,UAAS,KAAK,OAAO,EAAE,OAAO,IAAI,EAAE;AAAA,MAAA,CAC3D;AAAA,IACH;AAEA,SAAA,YAAiC,CAAC,SAAS;AAEzC,aAAOC,oBAAU;AAAA,QACf,QAAQ,6BAAM;AAAA,QACd,mBAAmB,6BAAM;AAAA,QACzB,MAAM,KAAK;AAAA,MAAA,CACL;AAAA,IACV;AAEA,SAAA,YAAiC,CAAC,SAAS;AAEzC,aAAOC,oBAAU;AAAA,QACf,QAAQ,6BAAM;AAAA,QACd,mBAAm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BAAU;AAAA,QACf,QAAQ,6BAAM;AAAA,QACd,mBAAmB,6BAAM;AAAA,QACzB,MAAM,KAAK;AAAA,MAAA,CACL;AAAA,IACV;AAEA,SAAA,gBAAiD,CAAC,SAAS;AACzD,aAAOC,cAAAA,cAAc,EAAE,GAAG,MAAM,MAAM,KAAK,IAAW;AAAA,IACxD;AAEA,SAAA,gBAAiD,CAAC,SAAS;AACzD,aAAOC,cAAAA,cAAc,EAAE,GAAG,MAAM,MAAM,KAAK,IAAW;AAAA,IACxD;AAEA,SAAA,cAAc,MAA8B;AAC1C,aAAOE,YAAY,YAAA,EAAE,MAAM,KAAK,UAAU;AAAA,IAC5C;AAAA,EAAA;AACF;AAEO,SAAS,gBAQd,SAiBA;AACO,SAAA,IAAI,UAOT,OAAO;AACX;AAEO,SAAS,gBAKd,MAGuB;AAChB,SAAA;AACT;AAkBO,MAAM,sBASH,MAcR;AAAA,EACA,YACE,SAsBA;AACM,UAAA;AAAA,MACJ,GAAI;AAAA,MACJ,IAAI;AAAA,IAAA,CACL;AAAA,EAAA;AAEL;;;;;;;;;;;"}
|
package/dist/cjs/route.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRootRoute, BaseRoute, BaseRouteApi, AnyContext, AnyRoute, AnyRouter, ConstrainLiteral, ErrorComponentProps, NotFoundError, NotFoundRouteProps, RegisteredRouter, ResolveFullPath, ResolveId, ResolveParams, RootRouteId, RootRouteOptions, RouteConstraints, RouteIds, RouteMask, RouteOptions, RouteTypesById, Router, ToMaskOptions, UseNavigateResult } from '@tanstack/router-core';
|
|
2
2
|
import { UseLoaderDataRoute } from './useLoaderData.cjs';
|
|
3
3
|
import { UseMatchRoute } from './useMatch.cjs';
|
|
4
4
|
import { UseLoaderDepsRoute } from './useLoaderDeps.cjs';
|
|
@@ -24,8 +24,7 @@ declare module '@tanstack/router-core' {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
export declare function getRouteApi<const TId, TRouter extends AnyRouter = RegisteredRouter>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>): RouteApi<TId, TRouter>;
|
|
27
|
-
export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
28
|
-
id: TId;
|
|
27
|
+
export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> extends BaseRouteApi<TId, TRouter> {
|
|
29
28
|
/**
|
|
30
29
|
* @deprecated Use the `getRouteApi` function instead.
|
|
31
30
|
*/
|
|
@@ -41,43 +40,11 @@ export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter>
|
|
|
41
40
|
useNavigate: () => UseNavigateResult<RouteTypesById<TRouter, TId>["fullPath"]>;
|
|
42
41
|
notFound: (opts?: NotFoundError) => NotFoundError;
|
|
43
42
|
}
|
|
44
|
-
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown>
|
|
45
|
-
isRoot: TParentRoute extends AnyRoute ? true : false;
|
|
46
|
-
options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>;
|
|
47
|
-
parentRoute: TParentRoute;
|
|
48
|
-
private _id;
|
|
49
|
-
private _path;
|
|
50
|
-
private _fullPath;
|
|
51
|
-
private _to;
|
|
52
|
-
private _ssr;
|
|
53
|
-
get to(): TrimPathRight<TFullPath>;
|
|
54
|
-
get id(): TId;
|
|
55
|
-
get path(): TPath;
|
|
56
|
-
get fullPath(): TFullPath;
|
|
57
|
-
get ssr(): boolean;
|
|
58
|
-
children?: TChildren;
|
|
59
|
-
originalIndex?: number;
|
|
60
|
-
rank: number;
|
|
61
|
-
lazyFn?: () => Promise<CoreLazyRoute>;
|
|
62
|
-
_lazyPromise?: Promise<void>;
|
|
63
|
-
_componentsPromise?: Promise<Array<void>>;
|
|
43
|
+
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRoute<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
64
44
|
/**
|
|
65
45
|
* @deprecated Use the `createRoute` function instead.
|
|
66
46
|
*/
|
|
67
47
|
constructor(options?: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>);
|
|
68
|
-
types: RouteTypes<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes>;
|
|
69
|
-
init: (opts: {
|
|
70
|
-
originalIndex: number;
|
|
71
|
-
defaultSsr?: boolean;
|
|
72
|
-
}) => void;
|
|
73
|
-
addChildren: RouteAddChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
74
|
-
_addFileChildren: RouteAddFileChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
75
|
-
_addFileTypes: RouteAddFileTypesFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
76
|
-
updateLoader: <TNewLoaderFn>(options: {
|
|
77
|
-
loader: Constrain<TNewLoaderFn, RouteLoaderFn<TParentRoute, TCustomId, TParams, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>>;
|
|
78
|
-
}) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TNewLoaderFn, TChildren, TFileRouteTypes>;
|
|
79
|
-
update: (options: UpdatableRouteOptions<TParentRoute, TCustomId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>) => this;
|
|
80
|
-
lazy: RouteLazyFn<this>;
|
|
81
48
|
useMatch: UseMatchRoute<TId>;
|
|
82
49
|
useRouteContext: UseRouteContextRoute<TId>;
|
|
83
50
|
useSearch: UseSearchRoute<TId>;
|
|
@@ -86,26 +53,25 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
86
53
|
useLoaderData: UseLoaderDataRoute<TId>;
|
|
87
54
|
useNavigate: () => UseNavigateResult<TFullPath>;
|
|
88
55
|
}
|
|
89
|
-
export declare function createRoute<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>, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown>(options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn>):
|
|
56
|
+
export declare function createRoute<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>, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown>(options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn>): Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, AnyContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
90
57
|
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>;
|
|
91
58
|
export declare function createRootRouteWithContext<TRouterContext extends {}>(): <TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TSearchValidator = undefined, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined>(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>) => RootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, unknown, unknown>;
|
|
92
59
|
/**
|
|
93
60
|
* @deprecated Use the `createRootRouteWithContext` function instead.
|
|
94
61
|
*/
|
|
95
62
|
export declare const rootRouteWithContext: typeof createRootRouteWithContext;
|
|
96
|
-
export declare class RootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends
|
|
97
|
-
'/', // TPath
|
|
98
|
-
'/', // TFullPath
|
|
99
|
-
string, // TCustomId
|
|
100
|
-
RootRouteId, // TId
|
|
101
|
-
TSearchValidator, // TSearchValidator
|
|
102
|
-
{}, // TParams
|
|
103
|
-
TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, // TChildren
|
|
104
|
-
TFileRouteTypes> {
|
|
63
|
+
export declare class RootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
105
64
|
/**
|
|
106
65
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
107
66
|
*/
|
|
108
67
|
constructor(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>);
|
|
68
|
+
useMatch: UseMatchRoute<RootRouteId>;
|
|
69
|
+
useRouteContext: UseRouteContextRoute<RootRouteId>;
|
|
70
|
+
useSearch: UseSearchRoute<RootRouteId>;
|
|
71
|
+
useParams: UseParamsRoute<RootRouteId>;
|
|
72
|
+
useLoaderDeps: UseLoaderDepsRoute<RootRouteId>;
|
|
73
|
+
useLoaderData: UseLoaderDataRoute<RootRouteId>;
|
|
74
|
+
useNavigate: () => UseNavigateResult<"/">;
|
|
109
75
|
}
|
|
110
76
|
export declare function createRootRoute<TSearchValidator = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined>(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>): RootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, unknown, unknown>;
|
|
111
77
|
export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends string, TTo extends string>(opts: {
|
package/dist/esm/route.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRootRoute, BaseRoute, BaseRouteApi, AnyContext, AnyRoute, AnyRouter, ConstrainLiteral, ErrorComponentProps, NotFoundError, NotFoundRouteProps, RegisteredRouter, ResolveFullPath, ResolveId, ResolveParams, RootRouteId, RootRouteOptions, RouteConstraints, RouteIds, RouteMask, RouteOptions, RouteTypesById, Router, ToMaskOptions, UseNavigateResult } from '@tanstack/router-core';
|
|
2
2
|
import { UseLoaderDataRoute } from './useLoaderData.js';
|
|
3
3
|
import { UseMatchRoute } from './useMatch.js';
|
|
4
4
|
import { UseLoaderDepsRoute } from './useLoaderDeps.js';
|
|
@@ -24,8 +24,7 @@ declare module '@tanstack/router-core' {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
export declare function getRouteApi<const TId, TRouter extends AnyRouter = RegisteredRouter>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>): RouteApi<TId, TRouter>;
|
|
27
|
-
export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
28
|
-
id: TId;
|
|
27
|
+
export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> extends BaseRouteApi<TId, TRouter> {
|
|
29
28
|
/**
|
|
30
29
|
* @deprecated Use the `getRouteApi` function instead.
|
|
31
30
|
*/
|
|
@@ -41,43 +40,11 @@ export declare class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter>
|
|
|
41
40
|
useNavigate: () => UseNavigateResult<RouteTypesById<TRouter, TId>["fullPath"]>;
|
|
42
41
|
notFound: (opts?: NotFoundError) => NotFoundError;
|
|
43
42
|
}
|
|
44
|
-
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown>
|
|
45
|
-
isRoot: TParentRoute extends AnyRoute ? true : false;
|
|
46
|
-
options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>;
|
|
47
|
-
parentRoute: TParentRoute;
|
|
48
|
-
private _id;
|
|
49
|
-
private _path;
|
|
50
|
-
private _fullPath;
|
|
51
|
-
private _to;
|
|
52
|
-
private _ssr;
|
|
53
|
-
get to(): TrimPathRight<TFullPath>;
|
|
54
|
-
get id(): TId;
|
|
55
|
-
get path(): TPath;
|
|
56
|
-
get fullPath(): TFullPath;
|
|
57
|
-
get ssr(): boolean;
|
|
58
|
-
children?: TChildren;
|
|
59
|
-
originalIndex?: number;
|
|
60
|
-
rank: number;
|
|
61
|
-
lazyFn?: () => Promise<CoreLazyRoute>;
|
|
62
|
-
_lazyPromise?: Promise<void>;
|
|
63
|
-
_componentsPromise?: Promise<Array<void>>;
|
|
43
|
+
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator = undefined, in out TParams = ResolveParams<TPath>, in out TRouterContext = AnyContext, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRoute<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
64
44
|
/**
|
|
65
45
|
* @deprecated Use the `createRoute` function instead.
|
|
66
46
|
*/
|
|
67
47
|
constructor(options?: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn>);
|
|
68
|
-
types: RouteTypes<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes>;
|
|
69
|
-
init: (opts: {
|
|
70
|
-
originalIndex: number;
|
|
71
|
-
defaultSsr?: boolean;
|
|
72
|
-
}) => void;
|
|
73
|
-
addChildren: RouteAddChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
74
|
-
_addFileChildren: RouteAddFileChildrenFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TFileRouteTypes>;
|
|
75
|
-
_addFileTypes: RouteAddFileTypesFn<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
76
|
-
updateLoader: <TNewLoaderFn>(options: {
|
|
77
|
-
loader: Constrain<TNewLoaderFn, RouteLoaderFn<TParentRoute, TCustomId, TParams, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>>;
|
|
78
|
-
}) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TNewLoaderFn, TChildren, TFileRouteTypes>;
|
|
79
|
-
update: (options: UpdatableRouteOptions<TParentRoute, TCustomId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, TRouterContext, TRouteContextFn, TBeforeLoadFn>) => this;
|
|
80
|
-
lazy: RouteLazyFn<this>;
|
|
81
48
|
useMatch: UseMatchRoute<TId>;
|
|
82
49
|
useRouteContext: UseRouteContextRoute<TId>;
|
|
83
50
|
useSearch: UseSearchRoute<TId>;
|
|
@@ -86,26 +53,25 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
86
53
|
useLoaderData: UseLoaderDataRoute<TId>;
|
|
87
54
|
useNavigate: () => UseNavigateResult<TFullPath>;
|
|
88
55
|
}
|
|
89
|
-
export declare function createRoute<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>, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown>(options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn>):
|
|
56
|
+
export declare function createRoute<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>, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown>(options: RouteOptions<TParentRoute, TId, TCustomId, TFullPath, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn>): Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, AnyContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren>;
|
|
90
57
|
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>;
|
|
91
58
|
export declare function createRootRouteWithContext<TRouterContext extends {}>(): <TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TSearchValidator = undefined, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined>(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>) => RootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, unknown, unknown>;
|
|
92
59
|
/**
|
|
93
60
|
* @deprecated Use the `createRootRouteWithContext` function instead.
|
|
94
61
|
*/
|
|
95
62
|
export declare const rootRouteWithContext: typeof createRootRouteWithContext;
|
|
96
|
-
export declare class RootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends
|
|
97
|
-
'/', // TPath
|
|
98
|
-
'/', // TFullPath
|
|
99
|
-
string, // TCustomId
|
|
100
|
-
RootRouteId, // TId
|
|
101
|
-
TSearchValidator, // TSearchValidator
|
|
102
|
-
{}, // TParams
|
|
103
|
-
TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, // TChildren
|
|
104
|
-
TFileRouteTypes> {
|
|
63
|
+
export declare class RootRoute<in out TSearchValidator = undefined, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TLoaderDeps extends Record<string, any> = {}, in out TLoaderFn = undefined, in out TChildren = unknown, in out TFileRouteTypes = unknown> extends BaseRootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, TFileRouteTypes> {
|
|
105
64
|
/**
|
|
106
65
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
107
66
|
*/
|
|
108
67
|
constructor(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>);
|
|
68
|
+
useMatch: UseMatchRoute<RootRouteId>;
|
|
69
|
+
useRouteContext: UseRouteContextRoute<RootRouteId>;
|
|
70
|
+
useSearch: UseSearchRoute<RootRouteId>;
|
|
71
|
+
useParams: UseParamsRoute<RootRouteId>;
|
|
72
|
+
useLoaderDeps: UseLoaderDepsRoute<RootRouteId>;
|
|
73
|
+
useLoaderData: UseLoaderDataRoute<RootRouteId>;
|
|
74
|
+
useNavigate: () => UseNavigateResult<"/">;
|
|
109
75
|
}
|
|
110
76
|
export declare function createRootRoute<TSearchValidator = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined>(options?: RootRouteOptions<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn>): RootRoute<TSearchValidator, TRouterContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, unknown, unknown>;
|
|
111
77
|
export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends string, TTo extends string>(opts: {
|
package/dist/esm/route.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { notFound, rootRouteId, trimPathLeft, joinPaths } from "@tanstack/router-core";
|
|
1
|
+
import { BaseRouteApi, notFound, BaseRoute, BaseRootRoute } from "@tanstack/router-core";
|
|
3
2
|
import { useLoaderData } from "./useLoaderData.js";
|
|
4
3
|
import { useLoaderDeps } from "./useLoaderDeps.js";
|
|
5
4
|
import { useParams } from "./useParams.js";
|
|
@@ -10,11 +9,12 @@ import { useRouter } from "./useRouter.js";
|
|
|
10
9
|
function getRouteApi(id) {
|
|
11
10
|
return new RouteApi({ id });
|
|
12
11
|
}
|
|
13
|
-
class RouteApi {
|
|
12
|
+
class RouteApi extends BaseRouteApi {
|
|
14
13
|
/**
|
|
15
14
|
* @deprecated Use the `getRouteApi` function instead.
|
|
16
15
|
*/
|
|
17
16
|
constructor({ id }) {
|
|
17
|
+
super({ id });
|
|
18
18
|
this.useMatch = (opts) => {
|
|
19
19
|
return useMatch({
|
|
20
20
|
select: opts == null ? void 0 : opts.select,
|
|
@@ -55,77 +55,14 @@ class RouteApi {
|
|
|
55
55
|
this.notFound = (opts) => {
|
|
56
56
|
return notFound({ routeId: this.id, ...opts });
|
|
57
57
|
};
|
|
58
|
-
this.id = id;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
class Route {
|
|
60
|
+
class Route extends BaseRoute {
|
|
62
61
|
/**
|
|
63
62
|
* @deprecated Use the `createRoute` function instead.
|
|
64
63
|
*/
|
|
65
64
|
constructor(options) {
|
|
66
|
-
|
|
67
|
-
var _a, _b;
|
|
68
|
-
this.originalIndex = opts.originalIndex;
|
|
69
|
-
const options2 = this.options;
|
|
70
|
-
const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id);
|
|
71
|
-
this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a);
|
|
72
|
-
if (isRoot) {
|
|
73
|
-
this._path = rootRouteId;
|
|
74
|
-
} else {
|
|
75
|
-
invariant(
|
|
76
|
-
this.parentRoute,
|
|
77
|
-
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
let path = isRoot ? rootRouteId : options2.path;
|
|
81
|
-
if (path && path !== "/") {
|
|
82
|
-
path = trimPathLeft(path);
|
|
83
|
-
}
|
|
84
|
-
const customId = (options2 == null ? void 0 : options2.id) || path;
|
|
85
|
-
let id = isRoot ? rootRouteId : joinPaths([
|
|
86
|
-
this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id,
|
|
87
|
-
customId
|
|
88
|
-
]);
|
|
89
|
-
if (path === rootRouteId) {
|
|
90
|
-
path = "/";
|
|
91
|
-
}
|
|
92
|
-
if (id !== rootRouteId) {
|
|
93
|
-
id = joinPaths(["/", id]);
|
|
94
|
-
}
|
|
95
|
-
const fullPath = id === rootRouteId ? "/" : joinPaths([this.parentRoute.fullPath, path]);
|
|
96
|
-
this._path = path;
|
|
97
|
-
this._id = id;
|
|
98
|
-
this._fullPath = fullPath;
|
|
99
|
-
this._to = fullPath;
|
|
100
|
-
this._ssr = (options2 == null ? void 0 : options2.ssr) ?? opts.defaultSsr ?? true;
|
|
101
|
-
};
|
|
102
|
-
this.addChildren = (children) => {
|
|
103
|
-
return this._addFileChildren(children);
|
|
104
|
-
};
|
|
105
|
-
this._addFileChildren = (children) => {
|
|
106
|
-
if (Array.isArray(children)) {
|
|
107
|
-
this.children = children;
|
|
108
|
-
}
|
|
109
|
-
if (typeof children === "object" && children !== null) {
|
|
110
|
-
this.children = Object.values(children);
|
|
111
|
-
}
|
|
112
|
-
return this;
|
|
113
|
-
};
|
|
114
|
-
this._addFileTypes = () => {
|
|
115
|
-
return this;
|
|
116
|
-
};
|
|
117
|
-
this.updateLoader = (options2) => {
|
|
118
|
-
Object.assign(this.options, options2);
|
|
119
|
-
return this;
|
|
120
|
-
};
|
|
121
|
-
this.update = (options2) => {
|
|
122
|
-
Object.assign(this.options, options2);
|
|
123
|
-
return this;
|
|
124
|
-
};
|
|
125
|
-
this.lazy = (lazyFn) => {
|
|
126
|
-
this.lazyFn = lazyFn;
|
|
127
|
-
return this;
|
|
128
|
-
};
|
|
65
|
+
super(options);
|
|
129
66
|
this.useMatch = (opts) => {
|
|
130
67
|
return useMatch({
|
|
131
68
|
select: opts == null ? void 0 : opts.select,
|
|
@@ -163,28 +100,6 @@ class Route {
|
|
|
163
100
|
this.useNavigate = () => {
|
|
164
101
|
return useNavigate({ from: this.fullPath });
|
|
165
102
|
};
|
|
166
|
-
this.options = options || {};
|
|
167
|
-
this.isRoot = !(options == null ? void 0 : options.getParentRoute);
|
|
168
|
-
invariant(
|
|
169
|
-
!((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)),
|
|
170
|
-
`Route cannot have both an 'id' and a 'path' option.`
|
|
171
|
-
);
|
|
172
|
-
this.$$typeof = Symbol.for("react.memo");
|
|
173
|
-
}
|
|
174
|
-
get to() {
|
|
175
|
-
return this._to;
|
|
176
|
-
}
|
|
177
|
-
get id() {
|
|
178
|
-
return this._id;
|
|
179
|
-
}
|
|
180
|
-
get path() {
|
|
181
|
-
return this._path;
|
|
182
|
-
}
|
|
183
|
-
get fullPath() {
|
|
184
|
-
return this._fullPath;
|
|
185
|
-
}
|
|
186
|
-
get ssr() {
|
|
187
|
-
return this._ssr;
|
|
188
103
|
}
|
|
189
104
|
}
|
|
190
105
|
function createRoute(options) {
|
|
@@ -196,12 +111,49 @@ function createRootRouteWithContext() {
|
|
|
196
111
|
};
|
|
197
112
|
}
|
|
198
113
|
const rootRouteWithContext = createRootRouteWithContext;
|
|
199
|
-
class RootRoute extends
|
|
114
|
+
class RootRoute extends BaseRootRoute {
|
|
200
115
|
/**
|
|
201
116
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
202
117
|
*/
|
|
203
118
|
constructor(options) {
|
|
204
119
|
super(options);
|
|
120
|
+
this.useMatch = (opts) => {
|
|
121
|
+
return useMatch({
|
|
122
|
+
select: opts == null ? void 0 : opts.select,
|
|
123
|
+
from: this.id,
|
|
124
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
this.useRouteContext = (opts) => {
|
|
128
|
+
return useMatch({
|
|
129
|
+
...opts,
|
|
130
|
+
from: this.id,
|
|
131
|
+
select: (d) => (opts == null ? void 0 : opts.select) ? opts.select(d.context) : d.context
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
this.useSearch = (opts) => {
|
|
135
|
+
return useSearch({
|
|
136
|
+
select: opts == null ? void 0 : opts.select,
|
|
137
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing,
|
|
138
|
+
from: this.id
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
this.useParams = (opts) => {
|
|
142
|
+
return useParams({
|
|
143
|
+
select: opts == null ? void 0 : opts.select,
|
|
144
|
+
structuralSharing: opts == null ? void 0 : opts.structuralSharing,
|
|
145
|
+
from: this.id
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
this.useLoaderDeps = (opts) => {
|
|
149
|
+
return useLoaderDeps({ ...opts, from: this.id });
|
|
150
|
+
};
|
|
151
|
+
this.useLoaderData = (opts) => {
|
|
152
|
+
return useLoaderData({ ...opts, from: this.id });
|
|
153
|
+
};
|
|
154
|
+
this.useNavigate = () => {
|
|
155
|
+
return useNavigate({ from: this.fullPath });
|
|
156
|
+
};
|
|
205
157
|
}
|
|
206
158
|
}
|
|
207
159
|
function createRootRoute(options) {
|
package/dist/esm/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport {\n joinPaths,\n notFound,\n rootRouteId,\n trimPathLeft,\n} from '@tanstack/router-core'\nimport { useLoaderData } from './useLoaderData'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { useNavigate } from './useNavigate'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n Constrain,\n ConstrainLiteral,\n LazyRoute as CoreLazyRoute,\n Route as CoreRoute,\n ErrorComponentProps,\n NotFoundError,\n NotFoundRouteProps,\n RegisteredRouter,\n ResolveFullPath,\n ResolveId,\n ResolveParams,\n RootRouteId,\n RootRouteOptions,\n RouteAddChildrenFn,\n RouteAddFileChildrenFn,\n RouteAddFileTypesFn,\n RouteConstraints,\n RouteIds,\n RouteLazyFn,\n RouteLoaderFn,\n RouteMask,\n RouteOptions,\n RoutePathOptionsIntersection,\n RouteTypes,\n RouteTypesById,\n Router,\n ToMaskOptions,\n TrimPathRight,\n UpdatableRouteOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseSearchRoute } from './useSearch'\nimport type * as React from 'react'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\ndeclare module '@tanstack/router-core' {\n export interface UpdatableRouteOptionsExtensions {\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n }\n\n export interface RouteExtensions<\n TId extends string,\n TFullPath extends string,\n > {\n useMatch: UseMatchRoute<TId>\n useRouteContext: UseRouteContextRoute<TId>\n useSearch: UseSearchRoute<TId>\n useParams: UseParamsRoute<TId>\n useLoaderDeps: UseLoaderDepsRoute<TId>\n useLoaderData: UseLoaderDataRoute<TId>\n useNavigate: () => UseNavigateResult<TFullPath>\n }\n}\n\nexport function getRouteApi<\n const TId,\n TRouter extends AnyRouter = RegisteredRouter,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return new RouteApi<TId, TRouter>({ id })\n}\n\nexport class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {\n id: TId\n\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n this.id = id as any\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts) => {\n return useMatch({\n from: this.id as any,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<\n RouteTypesById<TRouter, TId>['fullPath']\n > => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.id as string].fullPath })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> implements\n CoreRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n{\n isRoot: TParentRoute extends AnyRoute ? true : false\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n\n // The following properties are set up in this.init()\n parentRoute!: TParentRoute\n private _id!: TId\n private _path!: TPath\n private _fullPath!: TFullPath\n private _to!: TrimPathRight<TFullPath>\n private _ssr!: boolean\n\n public get to() {\n /* invariant(\n this._to,\n `trying to access property 'to' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._to\n }\n\n public get id() {\n /* invariant(\n this._id,\n `trying to access property 'id' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._id\n }\n\n public get path() {\n /* invariant(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.isRoot || this._id || this._path,\n `trying to access property 'path' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._path\n }\n\n public get fullPath() {\n /* invariant(\n this._fullPath,\n `trying to access property 'fullPath' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,\n )*/\n return this._fullPath\n }\n\n public get ssr() {\n return this._ssr\n }\n\n // Optional\n children?: TChildren\n originalIndex?: number\n rank!: number\n lazyFn?: () => Promise<CoreLazyRoute>\n _lazyPromise?: Promise<void>\n _componentsPromise?: Promise<Array<void>>\n\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) {\n this.options = (options as any) || {}\n\n this.isRoot = !options?.getParentRoute as any\n invariant(\n !((options as any)?.id && (options as any)?.path),\n `Route cannot have both an 'id' and a 'path' option.`,\n )\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n types!: RouteTypes<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n\n init = (opts: { originalIndex: number; defaultSsr?: boolean }): void => {\n this.originalIndex = opts.originalIndex\n\n const options = this.options as\n | (RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n > &\n RoutePathOptionsIntersection<TCustomId, TPath>)\n | undefined\n\n const isRoot = !options?.path && !options?.id\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n this.parentRoute = this.options.getParentRoute?.()\n\n if (isRoot) {\n this._path = rootRouteId as TPath\n } else {\n invariant(\n this.parentRoute,\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options?.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])\n\n this._path = path as TPath\n this._id = id as TId\n // this.customId = customId as TCustomId\n this._fullPath = fullPath as TFullPath\n this._to = fullPath as TrimPathRight<TFullPath>\n this._ssr = options?.ssr ?? opts.defaultSsr ?? true\n }\n\n addChildren: RouteAddChildrenFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes\n > = (children) => {\n return this._addFileChildren(children) as any\n }\n\n _addFileChildren: RouteAddFileChildrenFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TFileRouteTypes\n > = (children) => {\n if (Array.isArray(children)) {\n this.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n this.children = Object.values(children) as TChildren\n }\n\n return this as any\n }\n\n _addFileTypes: RouteAddFileTypesFn<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n > = () => {\n return this as any\n }\n\n updateLoader = <TNewLoaderFn>(options: {\n loader: Constrain<\n TNewLoaderFn,\n RouteLoaderFn<\n TParentRoute,\n TCustomId,\n TParams,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >\n >\n }) => {\n Object.assign(this.options, options)\n return this as unknown as Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TNewLoaderFn,\n TChildren,\n TFileRouteTypes\n >\n }\n\n update = (\n options: UpdatableRouteOptions<\n TParentRoute,\n TCustomId,\n TFullPath,\n TParams,\n TSearchValidator,\n TLoaderFn,\n TLoaderDeps,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ): this => {\n Object.assign(this.options, options)\n return this\n }\n\n lazy: RouteLazyFn<this> = (lazyFn) => {\n this.lazyFn = lazyFn\n return this\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts?) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n): CoreRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n unknown\n> {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends Route<\n any, // TParentRoute\n '/', // TPath\n '/', // TFullPath\n string, // TCustomId\n RootRouteId, // TId\n TSearchValidator, // TSearchValidator\n {}, // TParams\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren, // TChildren\n TFileRouteTypes\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) {\n super(options as any)\n }\n}\n\nexport function createRootRoute<\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n) {\n return new RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options)\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends string,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never', boolean>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TRouterContext = AnyContext,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n string,\n string,\n TSearchValidator,\n {},\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'caseSensitive'\n | 'parseParams'\n | 'stringifyParams'\n | 'path'\n | 'id'\n | 'params'\n >,\n ) {\n super({\n ...(options as any),\n id: '404',\n })\n }\n}\n"],"names":["options"],"mappings":";;;;;;;;;AA+EO,SAAS,YAGd,IAA2D;AAC3D,SAAO,IAAI,SAAuB,EAAE,IAAI;AAC1C;AAEO,MAAM,SAA4D;AAAA;AAAA;AAAA;AAAA,EAMvE,YAAY,EAAE,MAAmB;AAIjC,SAAA,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AS,EAAC,mCAAS;AACxB;AAAA,MACE,GAAG,mCAAiB,QAAO,mCAAiB;AAAA,MAC5C;AAAA,IACF;AACE,SAAa,WAAW,OAAO,IAAI,YAAY;AAAA,EAAA;AAAA,EAvEnD,IAAW,KAAK;AAKd,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,IAAW,KAAK;AAKd,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,IAAW,OAAO;AAMhB,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,IAAW,WAAW;AAKpB,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,IAAW,MAAM;AACf,WAAO,KAAK;AAAA,EAAA;AAmShB;AAEO,SAAS,YAqBd,SA6BA;AACO,SAAA,IAAI,MAcT,OAAO;AACX;AAIO,SAAS,6BAAwD;AACtE,SAAO,CAOL,YAQG;AACH,WAAO,gBAOL,OAAc;AAAA,EAClB;AACF;AAKO,MAAM,uBAAuB;AAE7B,MAAM,kBASH,MAeR;AAAA;AAAA;AAAA;AAAA,EAIA,YACE,SAQA;AACA,UAAM,OAAc;AAAA,EAAA;AAExB;AAEO,SAAS,gBAQd,SAQA;AACO,SAAA,IAAI,UAOT,OAAO;AACX;AAEO,SAAS,gBAKd,MAGuB;AAChB,SAAA;AACT;AAkBO,MAAM,sBASH,MAcR;AAAA,EACA,YACE,SAsBA;AACM,UAAA;AAAA,MACJ,GAAI;AAAA,MACJ,IAAI;AAAA,IAAA,CACL;AAAA,EAAA;AAEL;"}
|
|
1
|
+
{"version":3,"file":"route.js","sources":["../../src/route.ts"],"sourcesContent":["import {\n BaseRootRoute,\n BaseRoute,\n BaseRouteApi,\n notFound,\n} from '@tanstack/router-core'\nimport { useLoaderData } from './useLoaderData'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useParams } from './useParams'\nimport { useSearch } from './useSearch'\nimport { useNavigate } from './useNavigate'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport type {\n AnyContext,\n AnyRoute,\n AnyRouter,\n ConstrainLiteral,\n ErrorComponentProps,\n NotFoundError,\n NotFoundRouteProps,\n RegisteredRouter,\n ResolveFullPath,\n ResolveId,\n ResolveParams,\n RootRouteId,\n RootRouteOptions,\n RouteConstraints,\n RouteIds,\n RouteMask,\n RouteOptions,\n RouteTypesById,\n Router,\n ToMaskOptions,\n UseNavigateResult,\n} from '@tanstack/router-core'\nimport type { UseLoaderDataRoute } from './useLoaderData'\nimport type { UseMatchRoute } from './useMatch'\nimport type { UseLoaderDepsRoute } from './useLoaderDeps'\nimport type { UseParamsRoute } from './useParams'\nimport type { UseSearchRoute } from './useSearch'\nimport type * as React from 'react'\nimport type { UseRouteContextRoute } from './useRouteContext'\n\ndeclare module '@tanstack/router-core' {\n export interface UpdatableRouteOptionsExtensions {\n component?: RouteComponent\n errorComponent?: false | null | ErrorRouteComponent\n notFoundComponent?: NotFoundRouteComponent\n pendingComponent?: RouteComponent\n }\n\n export interface RouteExtensions<\n TId extends string,\n TFullPath extends string,\n > {\n useMatch: UseMatchRoute<TId>\n useRouteContext: UseRouteContextRoute<TId>\n useSearch: UseSearchRoute<TId>\n useParams: UseParamsRoute<TId>\n useLoaderDeps: UseLoaderDepsRoute<TId>\n useLoaderData: UseLoaderDataRoute<TId>\n useNavigate: () => UseNavigateResult<TFullPath>\n }\n}\n\nexport function getRouteApi<\n const TId,\n TRouter extends AnyRouter = RegisteredRouter,\n>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {\n return new RouteApi<TId, TRouter>({ id })\n}\n\nexport class RouteApi<\n TId,\n TRouter extends AnyRouter = RegisteredRouter,\n> extends BaseRouteApi<TId, TRouter> {\n /**\n * @deprecated Use the `getRouteApi` function instead.\n */\n constructor({ id }: { id: TId }) {\n super({ id })\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts) => {\n return useMatch({\n from: this.id as any,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id, strict: false } as any)\n }\n\n useNavigate = (): UseNavigateResult<\n RouteTypesById<TRouter, TId>['fullPath']\n > => {\n const router = useRouter()\n return useNavigate({ from: router.routesById[this.id as string].fullPath })\n }\n\n notFound = (opts?: NotFoundError) => {\n return notFound({ routeId: this.id as string, ...opts })\n }\n}\n\nexport class Route<\n in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n in out TPath extends RouteConstraints['TPath'] = '/',\n in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n in out TCustomId extends RouteConstraints['TCustomId'] = string,\n in out TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n in out TSearchValidator = undefined,\n in out TParams = ResolveParams<TPath>,\n in out TRouterContext = AnyContext,\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends BaseRoute<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n> {\n /**\n * @deprecated Use the `createRoute` function instead.\n */\n constructor(\n options?: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n ) {\n super(options)\n }\n\n useMatch: UseMatchRoute<TId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<TId> = (opts?) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<TId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<TId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<TFullPath> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRoute<\n TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,\n TPath extends RouteConstraints['TPath'] = '/',\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n TPath\n >,\n TCustomId extends RouteConstraints['TCustomId'] = string,\n TId extends RouteConstraints['TId'] = ResolveId<\n TParentRoute,\n TCustomId,\n TPath\n >,\n TSearchValidator = undefined,\n TParams = ResolveParams<TPath>,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n>(\n options: RouteOptions<\n TParentRoute,\n TId,\n TCustomId,\n TFullPath,\n TPath,\n TSearchValidator,\n TParams,\n TLoaderDeps,\n TLoaderFn,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n return new Route<\n TParentRoute,\n TPath,\n TFullPath,\n TCustomId,\n TId,\n TSearchValidator,\n TParams,\n AnyContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n >(options)\n}\n\nexport type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>\n\nexport function createRootRouteWithContext<TRouterContext extends {}>() {\n return <\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n >(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) => {\n return createRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options as any)\n }\n}\n\n/**\n * @deprecated Use the `createRootRouteWithContext` function instead.\n */\nexport const rootRouteWithContext = createRootRouteWithContext\n\nexport class RootRoute<\n in out TSearchValidator = undefined,\n in out TRouterContext = {},\n in out TRouteContextFn = AnyContext,\n in out TBeforeLoadFn = AnyContext,\n in out TLoaderDeps extends Record<string, any> = {},\n in out TLoaderFn = undefined,\n in out TChildren = unknown,\n in out TFileRouteTypes = unknown,\n> extends BaseRootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren,\n TFileRouteTypes\n> {\n /**\n * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.\n */\n constructor(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n ) {\n super(options)\n }\n\n useMatch: UseMatchRoute<RootRouteId> = (opts) => {\n return useMatch({\n select: opts?.select,\n from: this.id,\n structuralSharing: opts?.structuralSharing,\n } as any) as any\n }\n\n useRouteContext: UseRouteContextRoute<RootRouteId> = (opts) => {\n return useMatch({\n ...opts,\n from: this.id,\n select: (d) => (opts?.select ? opts.select(d.context) : d.context),\n }) as any\n }\n\n useSearch: UseSearchRoute<RootRouteId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useSearch({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useParams: UseParamsRoute<RootRouteId> = (opts) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return useParams({\n select: opts?.select,\n structuralSharing: opts?.structuralSharing,\n from: this.id,\n } as any) as any\n }\n\n useLoaderDeps: UseLoaderDepsRoute<RootRouteId> = (opts) => {\n return useLoaderDeps({ ...opts, from: this.id } as any)\n }\n\n useLoaderData: UseLoaderDataRoute<RootRouteId> = (opts) => {\n return useLoaderData({ ...opts, from: this.id } as any)\n }\n\n useNavigate = (): UseNavigateResult<'/'> => {\n return useNavigate({ from: this.fullPath })\n }\n}\n\nexport function createRootRoute<\n TSearchValidator = undefined,\n TRouterContext = {},\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n>(\n options?: RootRouteOptions<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >,\n): RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n unknown,\n unknown\n> {\n return new RootRoute<\n TSearchValidator,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn\n >(options)\n}\n\nexport function createRouteMask<\n TRouteTree extends AnyRoute,\n TFrom extends string,\n TTo extends string,\n>(\n opts: {\n routeTree: TRouteTree\n } & ToMaskOptions<Router<TRouteTree, 'never', boolean>, TFrom, TTo>,\n): RouteMask<TRouteTree> {\n return opts as any\n}\n\nexport type ReactNode = any\n\nexport type SyncRouteComponent<TProps> =\n | ((props: TProps) => ReactNode)\n | React.LazyExoticComponent<(props: TProps) => ReactNode>\n\nexport type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {\n preload?: () => Promise<void>\n}\n\nexport type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>\n\nexport type ErrorRouteComponent = RouteComponent<ErrorComponentProps>\n\nexport type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>\n\nexport class NotFoundRoute<\n TParentRoute extends AnyRootRoute,\n TRouterContext = AnyContext,\n TRouteContextFn = AnyContext,\n TBeforeLoadFn = AnyContext,\n TSearchValidator = undefined,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderFn = undefined,\n TChildren = unknown,\n> extends Route<\n TParentRoute,\n '/404',\n '/404',\n '404',\n '404',\n TSearchValidator,\n {},\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn,\n TLoaderDeps,\n TLoaderFn,\n TChildren\n> {\n constructor(\n options: Omit<\n RouteOptions<\n TParentRoute,\n string,\n string,\n string,\n string,\n TSearchValidator,\n {},\n TLoaderDeps,\n TLoaderFn,\n TRouterContext,\n TRouteContextFn,\n TBeforeLoadFn\n >,\n | 'caseSensitive'\n | 'parseParams'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X;AAEO,SAAS,gBAKd,MAGuB;AAChB,SAAA;AACT;AAkBO,MAAM,sBASH,MAcR;AAAA,EACA,YACE,SAsBA;AACM,UAAA;AAAA,MACJ,GAAI;AAAA,MACJ,IAAI;AAAA,IAAA,CACL;AAAA,EAAA;AAEL;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.114.
|
|
3
|
+
"version": "1.114.24",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"tiny-invariant": "^1.3.3",
|
|
55
55
|
"tiny-warning": "^1.0.3",
|
|
56
56
|
"@tanstack/history": "1.114.22",
|
|
57
|
-
"@tanstack/router-core": "1.114.
|
|
57
|
+
"@tanstack/router-core": "1.114.24"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/route.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import invariant from 'tiny-invariant'
|
|
2
1
|
import {
|
|
3
|
-
|
|
2
|
+
BaseRootRoute,
|
|
3
|
+
BaseRoute,
|
|
4
|
+
BaseRouteApi,
|
|
4
5
|
notFound,
|
|
5
|
-
rootRouteId,
|
|
6
|
-
trimPathLeft,
|
|
7
6
|
} from '@tanstack/router-core'
|
|
8
7
|
import { useLoaderData } from './useLoaderData'
|
|
9
8
|
import { useLoaderDeps } from './useLoaderDeps'
|
|
@@ -16,10 +15,7 @@ import type {
|
|
|
16
15
|
AnyContext,
|
|
17
16
|
AnyRoute,
|
|
18
17
|
AnyRouter,
|
|
19
|
-
Constrain,
|
|
20
18
|
ConstrainLiteral,
|
|
21
|
-
LazyRoute as CoreLazyRoute,
|
|
22
|
-
Route as CoreRoute,
|
|
23
19
|
ErrorComponentProps,
|
|
24
20
|
NotFoundError,
|
|
25
21
|
NotFoundRouteProps,
|
|
@@ -29,22 +25,13 @@ import type {
|
|
|
29
25
|
ResolveParams,
|
|
30
26
|
RootRouteId,
|
|
31
27
|
RootRouteOptions,
|
|
32
|
-
RouteAddChildrenFn,
|
|
33
|
-
RouteAddFileChildrenFn,
|
|
34
|
-
RouteAddFileTypesFn,
|
|
35
28
|
RouteConstraints,
|
|
36
29
|
RouteIds,
|
|
37
|
-
RouteLazyFn,
|
|
38
|
-
RouteLoaderFn,
|
|
39
30
|
RouteMask,
|
|
40
31
|
RouteOptions,
|
|
41
|
-
RoutePathOptionsIntersection,
|
|
42
|
-
RouteTypes,
|
|
43
32
|
RouteTypesById,
|
|
44
33
|
Router,
|
|
45
34
|
ToMaskOptions,
|
|
46
|
-
TrimPathRight,
|
|
47
|
-
UpdatableRouteOptions,
|
|
48
35
|
UseNavigateResult,
|
|
49
36
|
} from '@tanstack/router-core'
|
|
50
37
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
@@ -84,14 +71,15 @@ export function getRouteApi<
|
|
|
84
71
|
return new RouteApi<TId, TRouter>({ id })
|
|
85
72
|
}
|
|
86
73
|
|
|
87
|
-
export class RouteApi<
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
export class RouteApi<
|
|
75
|
+
TId,
|
|
76
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
77
|
+
> extends BaseRouteApi<TId, TRouter> {
|
|
90
78
|
/**
|
|
91
79
|
* @deprecated Use the `getRouteApi` function instead.
|
|
92
80
|
*/
|
|
93
81
|
constructor({ id }: { id: TId }) {
|
|
94
|
-
|
|
82
|
+
super({ id })
|
|
95
83
|
}
|
|
96
84
|
|
|
97
85
|
useMatch: UseMatchRoute<TId> = (opts) => {
|
|
@@ -169,93 +157,22 @@ export class Route<
|
|
|
169
157
|
in out TLoaderFn = undefined,
|
|
170
158
|
in out TChildren = unknown,
|
|
171
159
|
in out TFileRouteTypes = unknown,
|
|
172
|
-
>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
>
|
|
189
|
-
{
|
|
190
|
-
isRoot: TParentRoute extends AnyRoute ? true : false
|
|
191
|
-
options: RouteOptions<
|
|
192
|
-
TParentRoute,
|
|
193
|
-
TId,
|
|
194
|
-
TCustomId,
|
|
195
|
-
TFullPath,
|
|
196
|
-
TPath,
|
|
197
|
-
TSearchValidator,
|
|
198
|
-
TParams,
|
|
199
|
-
TLoaderDeps,
|
|
200
|
-
TLoaderFn,
|
|
201
|
-
TRouterContext,
|
|
202
|
-
TRouteContextFn,
|
|
203
|
-
TBeforeLoadFn
|
|
204
|
-
>
|
|
205
|
-
|
|
206
|
-
// The following properties are set up in this.init()
|
|
207
|
-
parentRoute!: TParentRoute
|
|
208
|
-
private _id!: TId
|
|
209
|
-
private _path!: TPath
|
|
210
|
-
private _fullPath!: TFullPath
|
|
211
|
-
private _to!: TrimPathRight<TFullPath>
|
|
212
|
-
private _ssr!: boolean
|
|
213
|
-
|
|
214
|
-
public get to() {
|
|
215
|
-
/* invariant(
|
|
216
|
-
this._to,
|
|
217
|
-
`trying to access property 'to' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,
|
|
218
|
-
)*/
|
|
219
|
-
return this._to
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
public get id() {
|
|
223
|
-
/* invariant(
|
|
224
|
-
this._id,
|
|
225
|
-
`trying to access property 'id' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,
|
|
226
|
-
)*/
|
|
227
|
-
return this._id
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public get path() {
|
|
231
|
-
/* invariant(
|
|
232
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
233
|
-
this.isRoot || this._id || this._path,
|
|
234
|
-
`trying to access property 'path' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,
|
|
235
|
-
)*/
|
|
236
|
-
return this._path
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
public get fullPath() {
|
|
240
|
-
/* invariant(
|
|
241
|
-
this._fullPath,
|
|
242
|
-
`trying to access property 'fullPath' on a route which is not initialized yet. Route properties are only available after 'createRouter' completed.`,
|
|
243
|
-
)*/
|
|
244
|
-
return this._fullPath
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
public get ssr() {
|
|
248
|
-
return this._ssr
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Optional
|
|
252
|
-
children?: TChildren
|
|
253
|
-
originalIndex?: number
|
|
254
|
-
rank!: number
|
|
255
|
-
lazyFn?: () => Promise<CoreLazyRoute>
|
|
256
|
-
_lazyPromise?: Promise<void>
|
|
257
|
-
_componentsPromise?: Promise<Array<void>>
|
|
258
|
-
|
|
160
|
+
> extends BaseRoute<
|
|
161
|
+
TParentRoute,
|
|
162
|
+
TPath,
|
|
163
|
+
TFullPath,
|
|
164
|
+
TCustomId,
|
|
165
|
+
TId,
|
|
166
|
+
TSearchValidator,
|
|
167
|
+
TParams,
|
|
168
|
+
TRouterContext,
|
|
169
|
+
TRouteContextFn,
|
|
170
|
+
TBeforeLoadFn,
|
|
171
|
+
TLoaderDeps,
|
|
172
|
+
TLoaderFn,
|
|
173
|
+
TChildren,
|
|
174
|
+
TFileRouteTypes
|
|
175
|
+
> {
|
|
259
176
|
/**
|
|
260
177
|
* @deprecated Use the `createRoute` function instead.
|
|
261
178
|
*/
|
|
@@ -275,220 +192,7 @@ export class Route<
|
|
|
275
192
|
TBeforeLoadFn
|
|
276
193
|
>,
|
|
277
194
|
) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
this.isRoot = !options?.getParentRoute as any
|
|
281
|
-
invariant(
|
|
282
|
-
!((options as any)?.id && (options as any)?.path),
|
|
283
|
-
`Route cannot have both an 'id' and a 'path' option.`,
|
|
284
|
-
)
|
|
285
|
-
;(this as any).$$typeof = Symbol.for('react.memo')
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
types!: RouteTypes<
|
|
289
|
-
TParentRoute,
|
|
290
|
-
TPath,
|
|
291
|
-
TFullPath,
|
|
292
|
-
TCustomId,
|
|
293
|
-
TId,
|
|
294
|
-
TSearchValidator,
|
|
295
|
-
TParams,
|
|
296
|
-
TRouterContext,
|
|
297
|
-
TRouteContextFn,
|
|
298
|
-
TBeforeLoadFn,
|
|
299
|
-
TLoaderDeps,
|
|
300
|
-
TLoaderFn,
|
|
301
|
-
TChildren,
|
|
302
|
-
TFileRouteTypes
|
|
303
|
-
>
|
|
304
|
-
|
|
305
|
-
init = (opts: { originalIndex: number; defaultSsr?: boolean }): void => {
|
|
306
|
-
this.originalIndex = opts.originalIndex
|
|
307
|
-
|
|
308
|
-
const options = this.options as
|
|
309
|
-
| (RouteOptions<
|
|
310
|
-
TParentRoute,
|
|
311
|
-
TId,
|
|
312
|
-
TCustomId,
|
|
313
|
-
TFullPath,
|
|
314
|
-
TPath,
|
|
315
|
-
TSearchValidator,
|
|
316
|
-
TParams,
|
|
317
|
-
TLoaderDeps,
|
|
318
|
-
TLoaderFn,
|
|
319
|
-
TRouterContext,
|
|
320
|
-
TRouteContextFn,
|
|
321
|
-
TBeforeLoadFn
|
|
322
|
-
> &
|
|
323
|
-
RoutePathOptionsIntersection<TCustomId, TPath>)
|
|
324
|
-
| undefined
|
|
325
|
-
|
|
326
|
-
const isRoot = !options?.path && !options?.id
|
|
327
|
-
|
|
328
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
329
|
-
this.parentRoute = this.options.getParentRoute?.()
|
|
330
|
-
|
|
331
|
-
if (isRoot) {
|
|
332
|
-
this._path = rootRouteId as TPath
|
|
333
|
-
} else {
|
|
334
|
-
invariant(
|
|
335
|
-
this.parentRoute,
|
|
336
|
-
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
|
|
337
|
-
)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
let path: undefined | string = isRoot ? rootRouteId : options.path
|
|
341
|
-
|
|
342
|
-
// If the path is anything other than an index path, trim it up
|
|
343
|
-
if (path && path !== '/') {
|
|
344
|
-
path = trimPathLeft(path)
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const customId = options?.id || path
|
|
348
|
-
|
|
349
|
-
// Strip the parentId prefix from the first level of children
|
|
350
|
-
let id = isRoot
|
|
351
|
-
? rootRouteId
|
|
352
|
-
: joinPaths([
|
|
353
|
-
this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,
|
|
354
|
-
customId,
|
|
355
|
-
])
|
|
356
|
-
|
|
357
|
-
if (path === rootRouteId) {
|
|
358
|
-
path = '/'
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (id !== rootRouteId) {
|
|
362
|
-
id = joinPaths(['/', id])
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const fullPath =
|
|
366
|
-
id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])
|
|
367
|
-
|
|
368
|
-
this._path = path as TPath
|
|
369
|
-
this._id = id as TId
|
|
370
|
-
// this.customId = customId as TCustomId
|
|
371
|
-
this._fullPath = fullPath as TFullPath
|
|
372
|
-
this._to = fullPath as TrimPathRight<TFullPath>
|
|
373
|
-
this._ssr = options?.ssr ?? opts.defaultSsr ?? true
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
addChildren: RouteAddChildrenFn<
|
|
377
|
-
TParentRoute,
|
|
378
|
-
TPath,
|
|
379
|
-
TFullPath,
|
|
380
|
-
TCustomId,
|
|
381
|
-
TId,
|
|
382
|
-
TSearchValidator,
|
|
383
|
-
TParams,
|
|
384
|
-
TRouterContext,
|
|
385
|
-
TRouteContextFn,
|
|
386
|
-
TBeforeLoadFn,
|
|
387
|
-
TLoaderDeps,
|
|
388
|
-
TLoaderFn,
|
|
389
|
-
TFileRouteTypes
|
|
390
|
-
> = (children) => {
|
|
391
|
-
return this._addFileChildren(children) as any
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
_addFileChildren: RouteAddFileChildrenFn<
|
|
395
|
-
TParentRoute,
|
|
396
|
-
TPath,
|
|
397
|
-
TFullPath,
|
|
398
|
-
TCustomId,
|
|
399
|
-
TId,
|
|
400
|
-
TSearchValidator,
|
|
401
|
-
TParams,
|
|
402
|
-
TRouterContext,
|
|
403
|
-
TRouteContextFn,
|
|
404
|
-
TBeforeLoadFn,
|
|
405
|
-
TLoaderDeps,
|
|
406
|
-
TLoaderFn,
|
|
407
|
-
TFileRouteTypes
|
|
408
|
-
> = (children) => {
|
|
409
|
-
if (Array.isArray(children)) {
|
|
410
|
-
this.children = children as TChildren
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (typeof children === 'object' && children !== null) {
|
|
414
|
-
this.children = Object.values(children) as TChildren
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return this as any
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
_addFileTypes: RouteAddFileTypesFn<
|
|
421
|
-
TParentRoute,
|
|
422
|
-
TPath,
|
|
423
|
-
TFullPath,
|
|
424
|
-
TCustomId,
|
|
425
|
-
TId,
|
|
426
|
-
TSearchValidator,
|
|
427
|
-
TParams,
|
|
428
|
-
TRouterContext,
|
|
429
|
-
TRouteContextFn,
|
|
430
|
-
TBeforeLoadFn,
|
|
431
|
-
TLoaderDeps,
|
|
432
|
-
TLoaderFn,
|
|
433
|
-
TChildren
|
|
434
|
-
> = () => {
|
|
435
|
-
return this as any
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
updateLoader = <TNewLoaderFn>(options: {
|
|
439
|
-
loader: Constrain<
|
|
440
|
-
TNewLoaderFn,
|
|
441
|
-
RouteLoaderFn<
|
|
442
|
-
TParentRoute,
|
|
443
|
-
TCustomId,
|
|
444
|
-
TParams,
|
|
445
|
-
TLoaderDeps,
|
|
446
|
-
TRouterContext,
|
|
447
|
-
TRouteContextFn,
|
|
448
|
-
TBeforeLoadFn
|
|
449
|
-
>
|
|
450
|
-
>
|
|
451
|
-
}) => {
|
|
452
|
-
Object.assign(this.options, options)
|
|
453
|
-
return this as unknown as Route<
|
|
454
|
-
TParentRoute,
|
|
455
|
-
TPath,
|
|
456
|
-
TFullPath,
|
|
457
|
-
TCustomId,
|
|
458
|
-
TId,
|
|
459
|
-
TSearchValidator,
|
|
460
|
-
TParams,
|
|
461
|
-
TRouterContext,
|
|
462
|
-
TRouteContextFn,
|
|
463
|
-
TBeforeLoadFn,
|
|
464
|
-
TLoaderDeps,
|
|
465
|
-
TNewLoaderFn,
|
|
466
|
-
TChildren,
|
|
467
|
-
TFileRouteTypes
|
|
468
|
-
>
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
update = (
|
|
472
|
-
options: UpdatableRouteOptions<
|
|
473
|
-
TParentRoute,
|
|
474
|
-
TCustomId,
|
|
475
|
-
TFullPath,
|
|
476
|
-
TParams,
|
|
477
|
-
TSearchValidator,
|
|
478
|
-
TLoaderFn,
|
|
479
|
-
TLoaderDeps,
|
|
480
|
-
TRouterContext,
|
|
481
|
-
TRouteContextFn,
|
|
482
|
-
TBeforeLoadFn
|
|
483
|
-
>,
|
|
484
|
-
): this => {
|
|
485
|
-
Object.assign(this.options, options)
|
|
486
|
-
return this
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
lazy: RouteLazyFn<this> = (lazyFn) => {
|
|
490
|
-
this.lazyFn = lazyFn
|
|
491
|
-
return this
|
|
195
|
+
super(options)
|
|
492
196
|
}
|
|
493
197
|
|
|
494
198
|
useMatch: UseMatchRoute<TId> = (opts) => {
|
|
@@ -573,7 +277,7 @@ export function createRoute<
|
|
|
573
277
|
TRouteContextFn,
|
|
574
278
|
TBeforeLoadFn
|
|
575
279
|
>,
|
|
576
|
-
):
|
|
280
|
+
): Route<
|
|
577
281
|
TParentRoute,
|
|
578
282
|
TPath,
|
|
579
283
|
TFullPath,
|
|
@@ -586,8 +290,7 @@ export function createRoute<
|
|
|
586
290
|
TBeforeLoadFn,
|
|
587
291
|
TLoaderDeps,
|
|
588
292
|
TLoaderFn,
|
|
589
|
-
TChildren
|
|
590
|
-
unknown
|
|
293
|
+
TChildren
|
|
591
294
|
> {
|
|
592
295
|
return new Route<
|
|
593
296
|
TParentRoute,
|
|
@@ -650,20 +353,14 @@ export class RootRoute<
|
|
|
650
353
|
in out TLoaderFn = undefined,
|
|
651
354
|
in out TChildren = unknown,
|
|
652
355
|
in out TFileRouteTypes = unknown,
|
|
653
|
-
> extends
|
|
654
|
-
|
|
655
|
-
'/', // TPath
|
|
656
|
-
'/', // TFullPath
|
|
657
|
-
string, // TCustomId
|
|
658
|
-
RootRouteId, // TId
|
|
659
|
-
TSearchValidator, // TSearchValidator
|
|
660
|
-
{}, // TParams
|
|
356
|
+
> extends BaseRootRoute<
|
|
357
|
+
TSearchValidator,
|
|
661
358
|
TRouterContext,
|
|
662
359
|
TRouteContextFn,
|
|
663
360
|
TBeforeLoadFn,
|
|
664
361
|
TLoaderDeps,
|
|
665
362
|
TLoaderFn,
|
|
666
|
-
TChildren,
|
|
363
|
+
TChildren,
|
|
667
364
|
TFileRouteTypes
|
|
668
365
|
> {
|
|
669
366
|
/**
|
|
@@ -679,7 +376,53 @@ export class RootRoute<
|
|
|
679
376
|
TLoaderFn
|
|
680
377
|
>,
|
|
681
378
|
) {
|
|
682
|
-
super(options
|
|
379
|
+
super(options)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
useMatch: UseMatchRoute<RootRouteId> = (opts) => {
|
|
383
|
+
return useMatch({
|
|
384
|
+
select: opts?.select,
|
|
385
|
+
from: this.id,
|
|
386
|
+
structuralSharing: opts?.structuralSharing,
|
|
387
|
+
} as any) as any
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
useRouteContext: UseRouteContextRoute<RootRouteId> = (opts) => {
|
|
391
|
+
return useMatch({
|
|
392
|
+
...opts,
|
|
393
|
+
from: this.id,
|
|
394
|
+
select: (d) => (opts?.select ? opts.select(d.context) : d.context),
|
|
395
|
+
}) as any
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
useSearch: UseSearchRoute<RootRouteId> = (opts) => {
|
|
399
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
400
|
+
return useSearch({
|
|
401
|
+
select: opts?.select,
|
|
402
|
+
structuralSharing: opts?.structuralSharing,
|
|
403
|
+
from: this.id,
|
|
404
|
+
} as any) as any
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
useParams: UseParamsRoute<RootRouteId> = (opts) => {
|
|
408
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
409
|
+
return useParams({
|
|
410
|
+
select: opts?.select,
|
|
411
|
+
structuralSharing: opts?.structuralSharing,
|
|
412
|
+
from: this.id,
|
|
413
|
+
} as any) as any
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
useLoaderDeps: UseLoaderDepsRoute<RootRouteId> = (opts) => {
|
|
417
|
+
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
useLoaderData: UseLoaderDataRoute<RootRouteId> = (opts) => {
|
|
421
|
+
return useLoaderData({ ...opts, from: this.id } as any)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
useNavigate = (): UseNavigateResult<'/'> => {
|
|
425
|
+
return useNavigate({ from: this.fullPath })
|
|
683
426
|
}
|
|
684
427
|
}
|
|
685
428
|
|
|
@@ -699,7 +442,16 @@ export function createRootRoute<
|
|
|
699
442
|
TLoaderDeps,
|
|
700
443
|
TLoaderFn
|
|
701
444
|
>,
|
|
702
|
-
)
|
|
445
|
+
): RootRoute<
|
|
446
|
+
TSearchValidator,
|
|
447
|
+
TRouterContext,
|
|
448
|
+
TRouteContextFn,
|
|
449
|
+
TBeforeLoadFn,
|
|
450
|
+
TLoaderDeps,
|
|
451
|
+
TLoaderFn,
|
|
452
|
+
unknown,
|
|
453
|
+
unknown
|
|
454
|
+
> {
|
|
703
455
|
return new RootRoute<
|
|
704
456
|
TSearchValidator,
|
|
705
457
|
TRouterContext,
|