@octanejs/tanstack-router 0.1.10 → 0.1.12
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 +26 -11
- package/src/Asset.tsrx +122 -0
- package/src/Asset.tsrx.d.ts +9 -0
- package/src/Await.tsrx +2 -1
- package/src/Await.tsrx.d.ts +8 -6
- package/src/Body.ts +31 -0
- package/src/CatchBoundary.tsrx +1 -3
- package/src/ClientOnly.tsrx +4 -2
- 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 +25 -7
- package/src/Link.tsrx.d.ts +3 -4
- package/src/Match.tsrx +40 -13
- package/src/Matches.tsrx +7 -7
- package/src/Outlet.tsrx +3 -3
- package/src/RouteNotFound.tsrx +1 -1
- package/src/RouterProvider.tsrx +2 -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 +6 -3
- 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 +108 -0
- package/src/headContentUtils.ts +172 -0
- package/src/hooks.ts +151 -0
- package/src/index.ts +84 -4
- package/src/lazyRouteComponent.ts +2 -1
- package/src/link.ts +25 -4
- package/src/linkTypes.ts +95 -0
- package/src/not-found.tsrx +2 -2
- package/src/octane-compiler.d.ts +12 -0
- package/src/route.ts +438 -42
- 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 +2 -1
- package/src/useRouterState.ts +20 -0
package/src/route.ts
CHANGED
|
@@ -8,9 +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 {
|
|
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';
|
|
12
37
|
import { createElement } from 'octane';
|
|
13
|
-
import type {
|
|
38
|
+
import type { ComponentBody } from 'octane';
|
|
14
39
|
import {
|
|
15
40
|
useMatch,
|
|
16
41
|
useParams,
|
|
@@ -23,6 +48,15 @@ import {
|
|
|
23
48
|
import { useRouter } from './context';
|
|
24
49
|
import { splitSlot, subSlot } from './internal';
|
|
25
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';
|
|
26
60
|
|
|
27
61
|
// ── Component types (react-router's route.tsx, on octane renderables) ────────
|
|
28
62
|
// Octane analog of React's `ErrorInfo` (octane reports no component stacks).
|
|
@@ -31,7 +65,13 @@ export type ErrorInfo = {
|
|
|
31
65
|
digest?: string | null;
|
|
32
66
|
};
|
|
33
67
|
|
|
34
|
-
export
|
|
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'];
|
|
35
75
|
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
36
76
|
preload?: () => Promise<void>;
|
|
37
77
|
};
|
|
@@ -50,15 +90,15 @@ declare module '@tanstack/router-core' {
|
|
|
50
90
|
pendingComponent?: RouteComponent;
|
|
51
91
|
}
|
|
52
92
|
interface RootRouteOptionsExtensions {
|
|
53
|
-
shellComponent?:
|
|
93
|
+
shellComponent?: ComponentBody<{ children?: unknown }>;
|
|
54
94
|
}
|
|
55
95
|
interface RouterOptionsExtensions {
|
|
56
96
|
defaultComponent?: RouteComponent;
|
|
57
97
|
defaultErrorComponent?: ErrorRouteComponent;
|
|
58
98
|
defaultPendingComponent?: RouteComponent;
|
|
59
99
|
defaultNotFoundComponent?: NotFoundRouteComponent;
|
|
60
|
-
Wrap?:
|
|
61
|
-
InnerWrap?:
|
|
100
|
+
Wrap?: ComponentBody<{ children?: unknown }>;
|
|
101
|
+
InnerWrap?: ComponentBody<{ children?: unknown }>;
|
|
62
102
|
defaultOnCatch?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
63
103
|
}
|
|
64
104
|
}
|
|
@@ -114,75 +154,431 @@ function attachRouteHooks(self: any, strictLoaderHooks: boolean): void {
|
|
|
114
154
|
};
|
|
115
155
|
}
|
|
116
156
|
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
) {
|
|
119
258
|
super(options);
|
|
120
259
|
attachRouteHooks(this, true);
|
|
121
|
-
(this
|
|
122
|
-
const [, slot] = splitSlot(args);
|
|
123
|
-
return useNavigate({ from: (this as any).fullPath }, subSlot(slot, 'r:n'));
|
|
124
|
-
};
|
|
125
|
-
(this as any).Link = (props: any) =>
|
|
126
|
-
createElement(Link as any, { from: (this as any).fullPath, ...props });
|
|
260
|
+
attachRouteNavigation(this);
|
|
127
261
|
}
|
|
128
262
|
}
|
|
129
263
|
|
|
130
|
-
export class RootRoute
|
|
131
|
-
|
|
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
|
+
) {
|
|
132
332
|
super(options);
|
|
133
333
|
attachRouteHooks(this, true);
|
|
134
|
-
(this
|
|
135
|
-
const [, slot] = splitSlot(args);
|
|
136
|
-
return useNavigate({ from: (this as any).fullPath }, subSlot(slot, 'r:n'));
|
|
137
|
-
};
|
|
138
|
-
(this as any).Link = (props: any) =>
|
|
139
|
-
createElement(Link as any, { from: (this as any).fullPath, ...props });
|
|
334
|
+
attachRouteNavigation(this);
|
|
140
335
|
}
|
|
141
336
|
}
|
|
142
337
|
|
|
143
|
-
export function createRoute
|
|
144
|
-
|
|
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);
|
|
145
395
|
}
|
|
146
396
|
|
|
147
|
-
export function createRootRoute
|
|
148
|
-
|
|
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);
|
|
149
436
|
}
|
|
150
437
|
|
|
151
438
|
// `createRootRouteWithContext<TContext>()` is a curried type-only helper that just
|
|
152
439
|
// returns `createRootRoute` — the context is a compile-time concern.
|
|
153
|
-
export function createRootRouteWithContext<
|
|
154
|
-
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);
|
|
155
465
|
}
|
|
156
466
|
|
|
467
|
+
/** @deprecated Use `createRootRouteWithContext` instead. */
|
|
468
|
+
export const rootRouteWithContext = createRootRouteWithContext;
|
|
469
|
+
|
|
157
470
|
// getRouteApi — route-bound hooks without importing the route (avoids circular
|
|
158
471
|
// imports in code-split files). Port of react-router's RouteApi class.
|
|
159
|
-
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
|
+
|
|
160
485
|
/** @deprecated Use the `getRouteApi` function instead. */
|
|
161
|
-
constructor({ id }: { id:
|
|
486
|
+
constructor({ id }: { id: TId }) {
|
|
162
487
|
super({ id });
|
|
163
488
|
attachRouteHooks(this, false);
|
|
164
|
-
|
|
489
|
+
this.useNavigate = ((...args: any[]) => {
|
|
165
490
|
const [, slot] = splitSlot(args);
|
|
166
491
|
const router = useRouter();
|
|
167
492
|
return useNavigate(
|
|
168
|
-
{ from: router.routesById
|
|
493
|
+
{ from: (router.routesById as any)[this.id as string].fullPath },
|
|
169
494
|
subSlot(slot, 'r:n'),
|
|
170
495
|
);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
(this as any).Link = (props: any) => {
|
|
496
|
+
}) as typeof this.useNavigate;
|
|
497
|
+
this.Link = ((props: Record<string, unknown>) => {
|
|
174
498
|
const router = useRouter();
|
|
175
|
-
const fullPath = router.routesById
|
|
499
|
+
const fullPath = (router.routesById as any)[this.id as string].fullPath;
|
|
176
500
|
return createElement(Link as any, { from: fullPath, ...props });
|
|
177
|
-
};
|
|
501
|
+
}) as unknown as typeof this.Link;
|
|
178
502
|
}
|
|
503
|
+
|
|
504
|
+
notFound = (opts?: NotFoundError) => notFound({ routeId: this.id, ...opts } as NotFoundError);
|
|
179
505
|
}
|
|
180
506
|
|
|
181
|
-
export function getRouteApi
|
|
182
|
-
|
|
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 });
|
|
183
511
|
}
|
|
184
512
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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;
|
|
525
|
+
}
|
|
526
|
+
|
|
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
|
+
}
|
|
188
584
|
}
|