@octanejs/tanstack-router 0.1.9 → 0.1.11
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/README.md +24 -11
- package/package.json +22 -7
- package/src/Asset.tsrx +121 -0
- package/src/Asset.tsrx.d.ts +9 -0
- package/src/Await.tsrx +9 -3
- package/src/Await.tsrx.d.ts +8 -6
- package/src/Body.ts +31 -0
- package/src/CatchBoundary.tsrx +21 -4
- package/src/CatchBoundary.tsrx.d.ts +10 -4
- package/src/ClientOnly.tsrx +6 -3
- package/src/Head.ts +22 -0
- package/src/HeadContent.tsrx +41 -0
- package/src/HeadContent.tsrx.d.ts +8 -0
- package/src/Html.ts +19 -0
- package/src/Link.tsrx +19 -4
- package/src/Link.tsrx.d.ts +3 -4
- package/src/Match.tsrx +61 -29
- package/src/MatchRoute.tsrx +6 -3
- package/src/Matches.tsrx +7 -7
- package/src/Navigate.tsrx +2 -1
- package/src/Outlet.tsrx +8 -6
- package/src/RouteNotFound.tsrx +2 -2
- package/src/RouterProvider.tsrx +12 -2
- package/src/RouterProvider.tsrx.d.ts +9 -5
- package/src/SafeFragment.tsrx +4 -1
- package/src/ScriptOnce.tsrx +23 -0
- package/src/ScriptOnce.tsrx.d.ts +3 -0
- package/src/Scripts.tsrx +42 -0
- package/src/Scripts.tsrx.d.ts +3 -0
- package/src/Transitioner.tsrx +15 -13
- package/src/assetKeys.ts +11 -0
- package/src/context.ts +5 -1
- package/src/externalHydration.ts +77 -0
- package/src/fileRoute.ts +277 -0
- package/src/frameworkTypes.ts +42 -0
- package/src/generator-plugin.d.ts +20 -0
- package/src/generator-plugin.js +100 -0
- package/src/headContentUtils.ts +172 -0
- package/src/hooks.ts +151 -0
- package/src/index.ts +95 -3
- package/src/lazyRouteComponent.ts +2 -1
- package/src/link.ts +25 -4
- package/src/linkTypes.ts +96 -0
- package/src/not-found.tsrx +19 -6
- package/src/not-found.tsrx.d.ts +5 -2
- package/src/octane-compiler.d.ts +12 -0
- package/src/route.ts +473 -36
- package/src/routeHookTypes.ts +228 -0
- package/src/router.ts +31 -6
- package/src/scriptContentUtils.ts +64 -0
- package/src/scroll-restoration.tsrx +16 -0
- package/src/scroll-restoration.tsrx.d.ts +3 -0
- package/src/ssr/RouterClient.tsrx +36 -0
- package/src/ssr/RouterClient.tsrx.d.ts +4 -0
- package/src/ssr/RouterServer.tsrx +6 -0
- package/src/ssr/RouterServer.tsrx.d.ts +4 -0
- package/src/ssr/client.ts +4 -0
- package/src/ssr/defaultRenderHandler.ts +11 -0
- package/src/ssr/defaultStreamHandler.ts +12 -0
- package/src/ssr/renderRouterToStream.ts +195 -0
- package/src/ssr/renderRouterToString.ts +58 -0
- package/src/ssr/server.ts +8 -0
- package/src/structuralSharing.ts +41 -0
- package/src/typePrimitives.ts +77 -0
- package/src/useAwaited.ts +7 -2
- package/src/useBlocker.tsrx +73 -8
- package/src/useBlocker.tsrx.d.ts +58 -2
- package/src/useRouterState.ts +20 -0
- package/src/useStore.ts +17 -6
package/src/route.ts
CHANGED
|
@@ -8,7 +8,34 @@
|
|
|
8
8
|
// `withSlot` and passes the call-site symbol as the trailing argument, which
|
|
9
9
|
// each accessor forwards to the hooks it composes.
|
|
10
10
|
import { BaseRoute, BaseRootRoute, BaseRouteApi, notFound } from '@tanstack/router-core';
|
|
11
|
+
import type {
|
|
12
|
+
AnyContext,
|
|
13
|
+
AnyRoute,
|
|
14
|
+
AnyRouter,
|
|
15
|
+
ConstrainLiteral,
|
|
16
|
+
ErrorComponentProps,
|
|
17
|
+
NotFoundError,
|
|
18
|
+
NotFoundRouteProps,
|
|
19
|
+
Register,
|
|
20
|
+
RegisteredRouter,
|
|
21
|
+
ResolveFullPath,
|
|
22
|
+
ResolveId,
|
|
23
|
+
ResolveParams,
|
|
24
|
+
RootRoute as RootRouteCore,
|
|
25
|
+
RootRouteId,
|
|
26
|
+
RootRouteOptions,
|
|
27
|
+
Route as RouteCore,
|
|
28
|
+
RouteConstraints,
|
|
29
|
+
RouteIds,
|
|
30
|
+
RouteMask,
|
|
31
|
+
RouteOptions,
|
|
32
|
+
RouteTypesById,
|
|
33
|
+
RouterCore,
|
|
34
|
+
ToMaskOptions,
|
|
35
|
+
UseNavigateResult,
|
|
36
|
+
} from '@tanstack/router-core';
|
|
11
37
|
import { createElement } from 'octane';
|
|
38
|
+
import type { ComponentBody } from 'octane';
|
|
12
39
|
import {
|
|
13
40
|
useMatch,
|
|
14
41
|
useParams,
|
|
@@ -21,6 +48,60 @@ import {
|
|
|
21
48
|
import { useRouter } from './context';
|
|
22
49
|
import { splitSlot, subSlot } from './internal';
|
|
23
50
|
import { Link } from './Link.tsrx';
|
|
51
|
+
import type {
|
|
52
|
+
UseLoaderDataRoute,
|
|
53
|
+
UseLoaderDepsRoute,
|
|
54
|
+
UseMatchRoute,
|
|
55
|
+
UseParamsRoute,
|
|
56
|
+
UseRouteContextRoute,
|
|
57
|
+
UseSearchRoute,
|
|
58
|
+
} from './routeHookTypes';
|
|
59
|
+
import type { LinkComponentRoute } from './linkTypes';
|
|
60
|
+
|
|
61
|
+
// ── Component types (react-router's route.tsx, on octane renderables) ────────
|
|
62
|
+
// Octane analog of React's `ErrorInfo` (octane reports no component stacks).
|
|
63
|
+
export type ErrorInfo = {
|
|
64
|
+
componentStack?: string | null;
|
|
65
|
+
digest?: string | null;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export interface DefaultRouteTypes<TProps> {
|
|
69
|
+
component: ComponentBody<TProps>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface RouteTypes<TProps> extends DefaultRouteTypes<TProps> {}
|
|
73
|
+
|
|
74
|
+
export type SyncRouteComponent<TProps> = RouteTypes<TProps>['component'];
|
|
75
|
+
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
76
|
+
preload?: () => Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
export type RouteComponent = AsyncRouteComponent<{}>;
|
|
79
|
+
export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>;
|
|
80
|
+
export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>;
|
|
81
|
+
|
|
82
|
+
// router-core leaves the framework-facing component options typed `unknown` and
|
|
83
|
+
// each binding narrows them via interface merging — react-router's route.tsx /
|
|
84
|
+
// router.tsx do exactly this with React types; this is the octane equivalent.
|
|
85
|
+
declare module '@tanstack/router-core' {
|
|
86
|
+
interface UpdatableRouteOptionsExtensions {
|
|
87
|
+
component?: RouteComponent;
|
|
88
|
+
errorComponent?: false | null | undefined | ErrorRouteComponent;
|
|
89
|
+
notFoundComponent?: NotFoundRouteComponent;
|
|
90
|
+
pendingComponent?: RouteComponent;
|
|
91
|
+
}
|
|
92
|
+
interface RootRouteOptionsExtensions {
|
|
93
|
+
shellComponent?: ComponentBody<{ children?: unknown }>;
|
|
94
|
+
}
|
|
95
|
+
interface RouterOptionsExtensions {
|
|
96
|
+
defaultComponent?: RouteComponent;
|
|
97
|
+
defaultErrorComponent?: ErrorRouteComponent;
|
|
98
|
+
defaultPendingComponent?: RouteComponent;
|
|
99
|
+
defaultNotFoundComponent?: NotFoundRouteComponent;
|
|
100
|
+
Wrap?: ComponentBody<{ children?: unknown }>;
|
|
101
|
+
InnerWrap?: ComponentBody<{ children?: unknown }>;
|
|
102
|
+
defaultOnCatch?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
24
105
|
|
|
25
106
|
// Attach the hook accessors to a route-shaped instance (Route / RootRoute /
|
|
26
107
|
// RouteApi). `strictLoaderHooks: false` is RouteApi's mode — its loader hooks
|
|
@@ -73,75 +154,431 @@ function attachRouteHooks(self: any, strictLoaderHooks: boolean): void {
|
|
|
73
154
|
};
|
|
74
155
|
}
|
|
75
156
|
|
|
76
|
-
|
|
77
|
-
|
|
157
|
+
function attachRouteNavigation(self: any): void {
|
|
158
|
+
self.useNavigate = (...args: any[]) => {
|
|
159
|
+
const [, slot] = splitSlot(args);
|
|
160
|
+
return useNavigate({ from: self.fullPath }, subSlot(slot, 'r:n'));
|
|
161
|
+
};
|
|
162
|
+
self.Link = (props: Record<string, unknown>) =>
|
|
163
|
+
createElement(Link as any, { from: self.fullPath, ...props });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class Route<
|
|
167
|
+
in out TRegister = unknown,
|
|
168
|
+
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
169
|
+
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
170
|
+
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>,
|
|
171
|
+
in out TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
172
|
+
in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>,
|
|
173
|
+
in out TSearchValidator = undefined,
|
|
174
|
+
in out TParams = ResolveParams<TPath>,
|
|
175
|
+
in out TRouterContext = AnyContext,
|
|
176
|
+
in out TRouteContextFn = AnyContext,
|
|
177
|
+
in out TBeforeLoadFn = AnyContext,
|
|
178
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
179
|
+
in out TLoaderFn = undefined,
|
|
180
|
+
in out TChildren = unknown,
|
|
181
|
+
in out TFileRouteTypes = unknown,
|
|
182
|
+
in out TSSR = unknown,
|
|
183
|
+
in out TServerMiddlewares = unknown,
|
|
184
|
+
in out THandlers = undefined,
|
|
185
|
+
>
|
|
186
|
+
extends BaseRoute<
|
|
187
|
+
TRegister,
|
|
188
|
+
TParentRoute,
|
|
189
|
+
TPath,
|
|
190
|
+
TFullPath,
|
|
191
|
+
TCustomId,
|
|
192
|
+
TId,
|
|
193
|
+
TSearchValidator,
|
|
194
|
+
TParams,
|
|
195
|
+
TRouterContext,
|
|
196
|
+
TRouteContextFn,
|
|
197
|
+
TBeforeLoadFn,
|
|
198
|
+
TLoaderDeps,
|
|
199
|
+
TLoaderFn,
|
|
200
|
+
TChildren,
|
|
201
|
+
TFileRouteTypes,
|
|
202
|
+
TSSR,
|
|
203
|
+
TServerMiddlewares,
|
|
204
|
+
THandlers
|
|
205
|
+
>
|
|
206
|
+
implements
|
|
207
|
+
RouteCore<
|
|
208
|
+
TRegister,
|
|
209
|
+
TParentRoute,
|
|
210
|
+
TPath,
|
|
211
|
+
TFullPath,
|
|
212
|
+
TCustomId,
|
|
213
|
+
TId,
|
|
214
|
+
TSearchValidator,
|
|
215
|
+
TParams,
|
|
216
|
+
TRouterContext,
|
|
217
|
+
TRouteContextFn,
|
|
218
|
+
TBeforeLoadFn,
|
|
219
|
+
TLoaderDeps,
|
|
220
|
+
TLoaderFn,
|
|
221
|
+
TChildren,
|
|
222
|
+
TFileRouteTypes,
|
|
223
|
+
TSSR,
|
|
224
|
+
TServerMiddlewares,
|
|
225
|
+
THandlers
|
|
226
|
+
>
|
|
227
|
+
{
|
|
228
|
+
declare useMatch: UseMatchRoute<TId>;
|
|
229
|
+
declare useRouteContext: UseRouteContextRoute<TId>;
|
|
230
|
+
declare useSearch: UseSearchRoute<TId>;
|
|
231
|
+
declare useParams: UseParamsRoute<TId>;
|
|
232
|
+
declare useLoaderDeps: UseLoaderDepsRoute<TId>;
|
|
233
|
+
declare useLoaderData: UseLoaderDataRoute<TId>;
|
|
234
|
+
declare useNavigate: () => UseNavigateResult<TFullPath>;
|
|
235
|
+
declare Link: LinkComponentRoute<TFullPath>;
|
|
236
|
+
|
|
237
|
+
/** @deprecated Use the `createRoute` function instead. */
|
|
238
|
+
constructor(
|
|
239
|
+
options?: RouteOptions<
|
|
240
|
+
TRegister,
|
|
241
|
+
TParentRoute,
|
|
242
|
+
TId,
|
|
243
|
+
TCustomId,
|
|
244
|
+
TFullPath,
|
|
245
|
+
TPath,
|
|
246
|
+
TSearchValidator,
|
|
247
|
+
TParams,
|
|
248
|
+
TLoaderDeps,
|
|
249
|
+
TLoaderFn,
|
|
250
|
+
TRouterContext,
|
|
251
|
+
TRouteContextFn,
|
|
252
|
+
TBeforeLoadFn,
|
|
253
|
+
TSSR,
|
|
254
|
+
TServerMiddlewares,
|
|
255
|
+
THandlers
|
|
256
|
+
>,
|
|
257
|
+
) {
|
|
78
258
|
super(options);
|
|
79
259
|
attachRouteHooks(this, true);
|
|
80
|
-
(this
|
|
81
|
-
const [, slot] = splitSlot(args);
|
|
82
|
-
return useNavigate({ from: (this as any).fullPath }, subSlot(slot, 'r:n'));
|
|
83
|
-
};
|
|
84
|
-
(this as any).Link = (props: any) =>
|
|
85
|
-
createElement(Link as any, { from: (this as any).fullPath, ...props });
|
|
260
|
+
attachRouteNavigation(this);
|
|
86
261
|
}
|
|
87
262
|
}
|
|
88
263
|
|
|
89
|
-
export class RootRoute
|
|
90
|
-
|
|
264
|
+
export class RootRoute<
|
|
265
|
+
in out TRegister = unknown,
|
|
266
|
+
in out TSearchValidator = undefined,
|
|
267
|
+
in out TRouterContext = {},
|
|
268
|
+
in out TRouteContextFn = AnyContext,
|
|
269
|
+
in out TBeforeLoadFn = AnyContext,
|
|
270
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
271
|
+
in out TLoaderFn = undefined,
|
|
272
|
+
in out TChildren = unknown,
|
|
273
|
+
in out TFileRouteTypes = unknown,
|
|
274
|
+
in out TSSR = unknown,
|
|
275
|
+
in out TServerMiddlewares = unknown,
|
|
276
|
+
in out THandlers = undefined,
|
|
277
|
+
>
|
|
278
|
+
extends BaseRootRoute<
|
|
279
|
+
TRegister,
|
|
280
|
+
TSearchValidator,
|
|
281
|
+
TRouterContext,
|
|
282
|
+
TRouteContextFn,
|
|
283
|
+
TBeforeLoadFn,
|
|
284
|
+
TLoaderDeps,
|
|
285
|
+
TLoaderFn,
|
|
286
|
+
TChildren,
|
|
287
|
+
TFileRouteTypes,
|
|
288
|
+
TSSR,
|
|
289
|
+
TServerMiddlewares,
|
|
290
|
+
THandlers
|
|
291
|
+
>
|
|
292
|
+
implements
|
|
293
|
+
RootRouteCore<
|
|
294
|
+
TRegister,
|
|
295
|
+
TSearchValidator,
|
|
296
|
+
TRouterContext,
|
|
297
|
+
TRouteContextFn,
|
|
298
|
+
TBeforeLoadFn,
|
|
299
|
+
TLoaderDeps,
|
|
300
|
+
TLoaderFn,
|
|
301
|
+
TChildren,
|
|
302
|
+
TFileRouteTypes,
|
|
303
|
+
TSSR,
|
|
304
|
+
TServerMiddlewares,
|
|
305
|
+
THandlers
|
|
306
|
+
>
|
|
307
|
+
{
|
|
308
|
+
declare useMatch: UseMatchRoute<RootRouteId>;
|
|
309
|
+
declare useRouteContext: UseRouteContextRoute<RootRouteId>;
|
|
310
|
+
declare useSearch: UseSearchRoute<RootRouteId>;
|
|
311
|
+
declare useParams: UseParamsRoute<RootRouteId>;
|
|
312
|
+
declare useLoaderDeps: UseLoaderDepsRoute<RootRouteId>;
|
|
313
|
+
declare useLoaderData: UseLoaderDataRoute<RootRouteId>;
|
|
314
|
+
declare useNavigate: () => UseNavigateResult<'/'>;
|
|
315
|
+
declare Link: LinkComponentRoute<'/'>;
|
|
316
|
+
|
|
317
|
+
/** @deprecated Use `createRootRoute()` instead. */
|
|
318
|
+
constructor(
|
|
319
|
+
options?: RootRouteOptions<
|
|
320
|
+
TRegister,
|
|
321
|
+
TSearchValidator,
|
|
322
|
+
TRouterContext,
|
|
323
|
+
TRouteContextFn,
|
|
324
|
+
TBeforeLoadFn,
|
|
325
|
+
TLoaderDeps,
|
|
326
|
+
TLoaderFn,
|
|
327
|
+
TSSR,
|
|
328
|
+
TServerMiddlewares,
|
|
329
|
+
THandlers
|
|
330
|
+
>,
|
|
331
|
+
) {
|
|
91
332
|
super(options);
|
|
92
333
|
attachRouteHooks(this, true);
|
|
93
|
-
(this
|
|
94
|
-
const [, slot] = splitSlot(args);
|
|
95
|
-
return useNavigate({ from: (this as any).fullPath }, subSlot(slot, 'r:n'));
|
|
96
|
-
};
|
|
97
|
-
(this as any).Link = (props: any) =>
|
|
98
|
-
createElement(Link as any, { from: (this as any).fullPath, ...props });
|
|
334
|
+
attachRouteNavigation(this);
|
|
99
335
|
}
|
|
100
336
|
}
|
|
101
337
|
|
|
102
|
-
export function createRoute
|
|
103
|
-
|
|
338
|
+
export function createRoute<
|
|
339
|
+
TRegister = unknown,
|
|
340
|
+
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
341
|
+
TPath extends RouteConstraints['TPath'] = '/',
|
|
342
|
+
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>,
|
|
343
|
+
TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
344
|
+
TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>,
|
|
345
|
+
TSearchValidator = undefined,
|
|
346
|
+
TParams = ResolveParams<TPath>,
|
|
347
|
+
TRouteContextFn = AnyContext,
|
|
348
|
+
TBeforeLoadFn = AnyContext,
|
|
349
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
350
|
+
TLoaderFn = undefined,
|
|
351
|
+
TChildren = unknown,
|
|
352
|
+
TSSR = unknown,
|
|
353
|
+
const TServerMiddlewares = unknown,
|
|
354
|
+
THandlers = undefined,
|
|
355
|
+
>(
|
|
356
|
+
options: RouteOptions<
|
|
357
|
+
TRegister,
|
|
358
|
+
TParentRoute,
|
|
359
|
+
TId,
|
|
360
|
+
TCustomId,
|
|
361
|
+
TFullPath,
|
|
362
|
+
TPath,
|
|
363
|
+
TSearchValidator,
|
|
364
|
+
TParams,
|
|
365
|
+
TLoaderDeps,
|
|
366
|
+
TLoaderFn,
|
|
367
|
+
AnyContext,
|
|
368
|
+
TRouteContextFn,
|
|
369
|
+
TBeforeLoadFn,
|
|
370
|
+
TSSR,
|
|
371
|
+
TServerMiddlewares,
|
|
372
|
+
THandlers
|
|
373
|
+
>,
|
|
374
|
+
): Route<
|
|
375
|
+
TRegister,
|
|
376
|
+
TParentRoute,
|
|
377
|
+
TPath,
|
|
378
|
+
TFullPath,
|
|
379
|
+
TCustomId,
|
|
380
|
+
TId,
|
|
381
|
+
TSearchValidator,
|
|
382
|
+
TParams,
|
|
383
|
+
AnyContext,
|
|
384
|
+
TRouteContextFn,
|
|
385
|
+
TBeforeLoadFn,
|
|
386
|
+
TLoaderDeps,
|
|
387
|
+
TLoaderFn,
|
|
388
|
+
TChildren,
|
|
389
|
+
unknown,
|
|
390
|
+
TSSR,
|
|
391
|
+
TServerMiddlewares,
|
|
392
|
+
THandlers
|
|
393
|
+
> {
|
|
394
|
+
return new Route(options as any);
|
|
104
395
|
}
|
|
105
396
|
|
|
106
|
-
export function createRootRoute
|
|
107
|
-
|
|
397
|
+
export function createRootRoute<
|
|
398
|
+
TRegister = Register,
|
|
399
|
+
TSearchValidator = undefined,
|
|
400
|
+
TRouterContext = {},
|
|
401
|
+
TRouteContextFn = AnyContext,
|
|
402
|
+
TBeforeLoadFn = AnyContext,
|
|
403
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
404
|
+
TLoaderFn = undefined,
|
|
405
|
+
TSSR = unknown,
|
|
406
|
+
const TServerMiddlewares = unknown,
|
|
407
|
+
THandlers = undefined,
|
|
408
|
+
>(
|
|
409
|
+
options?: RootRouteOptions<
|
|
410
|
+
TRegister,
|
|
411
|
+
TSearchValidator,
|
|
412
|
+
TRouterContext,
|
|
413
|
+
TRouteContextFn,
|
|
414
|
+
TBeforeLoadFn,
|
|
415
|
+
TLoaderDeps,
|
|
416
|
+
TLoaderFn,
|
|
417
|
+
TSSR,
|
|
418
|
+
TServerMiddlewares,
|
|
419
|
+
THandlers
|
|
420
|
+
>,
|
|
421
|
+
): RootRoute<
|
|
422
|
+
TRegister,
|
|
423
|
+
TSearchValidator,
|
|
424
|
+
TRouterContext,
|
|
425
|
+
TRouteContextFn,
|
|
426
|
+
TBeforeLoadFn,
|
|
427
|
+
TLoaderDeps,
|
|
428
|
+
TLoaderFn,
|
|
429
|
+
unknown,
|
|
430
|
+
unknown,
|
|
431
|
+
TSSR,
|
|
432
|
+
TServerMiddlewares,
|
|
433
|
+
THandlers
|
|
434
|
+
> {
|
|
435
|
+
return new RootRoute(options);
|
|
108
436
|
}
|
|
109
437
|
|
|
110
438
|
// `createRootRouteWithContext<TContext>()` is a curried type-only helper that just
|
|
111
439
|
// returns `createRootRoute` — the context is a compile-time concern.
|
|
112
|
-
export function createRootRouteWithContext<
|
|
113
|
-
return
|
|
440
|
+
export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
441
|
+
return <
|
|
442
|
+
TRegister = Register,
|
|
443
|
+
TRouteContextFn = AnyContext,
|
|
444
|
+
TBeforeLoadFn = AnyContext,
|
|
445
|
+
TSearchValidator = undefined,
|
|
446
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
447
|
+
TLoaderFn = undefined,
|
|
448
|
+
TSSR = unknown,
|
|
449
|
+
TServerMiddlewares = unknown,
|
|
450
|
+
THandlers = undefined,
|
|
451
|
+
>(
|
|
452
|
+
options?: RootRouteOptions<
|
|
453
|
+
TRegister,
|
|
454
|
+
TSearchValidator,
|
|
455
|
+
TRouterContext,
|
|
456
|
+
TRouteContextFn,
|
|
457
|
+
TBeforeLoadFn,
|
|
458
|
+
TLoaderDeps,
|
|
459
|
+
TLoaderFn,
|
|
460
|
+
TSSR,
|
|
461
|
+
TServerMiddlewares,
|
|
462
|
+
THandlers
|
|
463
|
+
>,
|
|
464
|
+
) => createRootRoute(options);
|
|
114
465
|
}
|
|
115
466
|
|
|
467
|
+
/** @deprecated Use `createRootRouteWithContext` instead. */
|
|
468
|
+
export const rootRouteWithContext = createRootRouteWithContext;
|
|
469
|
+
|
|
116
470
|
// getRouteApi — route-bound hooks without importing the route (avoids circular
|
|
117
471
|
// imports in code-split files). Port of react-router's RouteApi class.
|
|
118
|
-
export class RouteApi extends
|
|
472
|
+
export class RouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> extends BaseRouteApi<
|
|
473
|
+
TId,
|
|
474
|
+
TRouter
|
|
475
|
+
> {
|
|
476
|
+
declare useMatch: UseMatchRoute<TId>;
|
|
477
|
+
declare useRouteContext: UseRouteContextRoute<TId>;
|
|
478
|
+
declare useSearch: UseSearchRoute<TId>;
|
|
479
|
+
declare useParams: UseParamsRoute<TId>;
|
|
480
|
+
declare useLoaderDeps: UseLoaderDepsRoute<TId>;
|
|
481
|
+
declare useLoaderData: UseLoaderDataRoute<TId>;
|
|
482
|
+
declare useNavigate: () => UseNavigateResult<RouteTypesById<TRouter, TId>['fullPath']>;
|
|
483
|
+
declare Link: LinkComponentRoute<RouteTypesById<TRouter, TId>['fullPath']>;
|
|
484
|
+
|
|
119
485
|
/** @deprecated Use the `getRouteApi` function instead. */
|
|
120
|
-
constructor({ id }: { id:
|
|
486
|
+
constructor({ id }: { id: TId }) {
|
|
121
487
|
super({ id });
|
|
122
488
|
attachRouteHooks(this, false);
|
|
123
|
-
|
|
489
|
+
this.useNavigate = ((...args: any[]) => {
|
|
124
490
|
const [, slot] = splitSlot(args);
|
|
125
491
|
const router = useRouter();
|
|
126
492
|
return useNavigate(
|
|
127
|
-
{ from: router.routesById
|
|
493
|
+
{ from: (router.routesById as any)[this.id as string].fullPath },
|
|
128
494
|
subSlot(slot, 'r:n'),
|
|
129
495
|
);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
(this as any).Link = (props: any) => {
|
|
496
|
+
}) as typeof this.useNavigate;
|
|
497
|
+
this.Link = ((props: Record<string, unknown>) => {
|
|
133
498
|
const router = useRouter();
|
|
134
|
-
const fullPath = router.routesById
|
|
499
|
+
const fullPath = (router.routesById as any)[this.id as string].fullPath;
|
|
135
500
|
return createElement(Link as any, { from: fullPath, ...props });
|
|
136
|
-
};
|
|
501
|
+
}) as unknown as typeof this.Link;
|
|
137
502
|
}
|
|
503
|
+
|
|
504
|
+
notFound = (opts?: NotFoundError) => notFound({ routeId: this.id, ...opts } as NotFoundError);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export function getRouteApi<const TId, TRouter extends AnyRouter = RegisteredRouter>(
|
|
508
|
+
id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>,
|
|
509
|
+
) {
|
|
510
|
+
return new RouteApi<TId, TRouter>({ id });
|
|
138
511
|
}
|
|
139
512
|
|
|
140
|
-
export function
|
|
141
|
-
|
|
513
|
+
export function createRouteMask<
|
|
514
|
+
TRouteTree extends AnyRoute,
|
|
515
|
+
TFrom extends string,
|
|
516
|
+
TTo extends string,
|
|
517
|
+
>(
|
|
518
|
+
opts: { routeTree: TRouteTree } & ToMaskOptions<
|
|
519
|
+
RouterCore<TRouteTree, 'never', boolean>,
|
|
520
|
+
TFrom,
|
|
521
|
+
TTo
|
|
522
|
+
>,
|
|
523
|
+
): RouteMask<TRouteTree> {
|
|
524
|
+
return opts as any;
|
|
142
525
|
}
|
|
143
526
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
527
|
+
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
528
|
+
|
|
529
|
+
export class NotFoundRoute<
|
|
530
|
+
TRegister,
|
|
531
|
+
TParentRoute extends AnyRootRoute,
|
|
532
|
+
TRouterContext = AnyContext,
|
|
533
|
+
TRouteContextFn = AnyContext,
|
|
534
|
+
TBeforeLoadFn = AnyContext,
|
|
535
|
+
TSearchValidator = undefined,
|
|
536
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
537
|
+
TLoaderFn = undefined,
|
|
538
|
+
TChildren = unknown,
|
|
539
|
+
TSSR = unknown,
|
|
540
|
+
TServerMiddlewares = unknown,
|
|
541
|
+
> extends Route<
|
|
542
|
+
TRegister,
|
|
543
|
+
TParentRoute,
|
|
544
|
+
'/404',
|
|
545
|
+
'/404',
|
|
546
|
+
'404',
|
|
547
|
+
'404',
|
|
548
|
+
TSearchValidator,
|
|
549
|
+
{},
|
|
550
|
+
TRouterContext,
|
|
551
|
+
TRouteContextFn,
|
|
552
|
+
TBeforeLoadFn,
|
|
553
|
+
TLoaderDeps,
|
|
554
|
+
TLoaderFn,
|
|
555
|
+
TChildren,
|
|
556
|
+
unknown,
|
|
557
|
+
TSSR,
|
|
558
|
+
TServerMiddlewares
|
|
559
|
+
> {
|
|
560
|
+
constructor(
|
|
561
|
+
options: Omit<
|
|
562
|
+
RouteOptions<
|
|
563
|
+
TRegister,
|
|
564
|
+
TParentRoute,
|
|
565
|
+
string,
|
|
566
|
+
string,
|
|
567
|
+
string,
|
|
568
|
+
string,
|
|
569
|
+
TSearchValidator,
|
|
570
|
+
{},
|
|
571
|
+
TLoaderDeps,
|
|
572
|
+
TLoaderFn,
|
|
573
|
+
TRouterContext,
|
|
574
|
+
TRouteContextFn,
|
|
575
|
+
TBeforeLoadFn,
|
|
576
|
+
TSSR,
|
|
577
|
+
TServerMiddlewares
|
|
578
|
+
>,
|
|
579
|
+
'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id' | 'params'
|
|
580
|
+
>,
|
|
581
|
+
) {
|
|
582
|
+
super({ ...(options as any), id: '404' });
|
|
583
|
+
}
|
|
147
584
|
}
|