@tanstack/router-core 1.114.23 → 1.114.25
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/history.d.cts +8 -0
- package/dist/cjs/index.cjs +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -3
- package/dist/cjs/route.cjs +108 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/route.d.cts +54 -0
- package/dist/cjs/router.cjs +1695 -0
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +117 -55
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +11 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/route.d.ts +54 -0
- package/dist/esm/route.js +108 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/router.d.ts +117 -55
- package/dist/esm/router.js +1696 -1
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -1
- package/src/history.ts +9 -0
- package/src/index.ts +14 -4
- package/src/route.ts +368 -0
- package/src/router.ts +2511 -106
package/dist/esm/router.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { Store } from '@tanstack/store';
|
|
2
|
+
import { SearchParser, SearchSerializer } from './searchParams.js';
|
|
3
|
+
import { AnyRedirect, ResolvedRedirect } from './redirect.js';
|
|
4
|
+
import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
|
|
5
|
+
import { ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
|
|
1
6
|
import { ParsedLocation } from './location.js';
|
|
2
7
|
import { DeferredPromiseState } from './defer.js';
|
|
3
|
-
import { ControlledPromise, NoInfer, NonNullableUpdater, Updater } from './utils.js';
|
|
4
8
|
import { AnyContext, AnyRoute, AnyRouteWithContext, MakeRemountDepsOptionsUnion, RouteMask } from './route.js';
|
|
5
|
-
import { Store } from '@tanstack/store';
|
|
6
9
|
import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
|
|
7
|
-
import { AnyRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
|
|
8
|
-
import { AnyRedirect, ResolvedRedirect } from './redirect.js';
|
|
10
|
+
import { AnyRouteMatch, MakeRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
|
|
9
11
|
import { BuildLocationFn, CommitLocationOptions, NavigateFn } from './RouterProvider.js';
|
|
10
|
-
import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
|
|
11
12
|
import { Manifest } from './manifest.js';
|
|
12
13
|
import { StartSerializer } from './serializer.js';
|
|
13
14
|
import { AnySchema } from './validators.js';
|
|
14
15
|
import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
|
|
15
|
-
import {
|
|
16
|
+
import { NotFoundError } from './not-found.js';
|
|
16
17
|
declare global {
|
|
17
18
|
interface Window {
|
|
18
19
|
__TSR_ROUTER__?: AnyRouter;
|
|
@@ -385,8 +386,8 @@ export interface MatchedRoutesResult {
|
|
|
385
386
|
matchedRoutes: Array<AnyRoute>;
|
|
386
387
|
routeParams: Record<string, string>;
|
|
387
388
|
}
|
|
388
|
-
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<
|
|
389
|
-
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<
|
|
389
|
+
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
390
|
+
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
390
391
|
export type UpdateFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
|
|
391
392
|
export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
|
|
392
393
|
filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
|
|
@@ -430,53 +431,8 @@ export interface ServerSrr {
|
|
|
430
431
|
match: AnyRouteMatch;
|
|
431
432
|
}) => any;
|
|
432
433
|
}
|
|
433
|
-
export
|
|
434
|
-
|
|
435
|
-
options: RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
|
|
436
|
-
__store: Store<RouterState<TRouteTree>>;
|
|
437
|
-
navigate: NavigateFn;
|
|
438
|
-
history: TRouterHistory;
|
|
439
|
-
state: RouterState<TRouteTree>;
|
|
440
|
-
isServer: boolean;
|
|
441
|
-
clientSsr?: {
|
|
442
|
-
getStreamedValue: <T>(key: string) => T | undefined;
|
|
443
|
-
};
|
|
444
|
-
looseRoutesById: Record<string, AnyRoute>;
|
|
445
|
-
latestLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
446
|
-
isScrollRestoring: boolean;
|
|
447
|
-
resetNextScroll: boolean;
|
|
448
|
-
isScrollRestorationSetup: boolean;
|
|
449
|
-
ssr?: {
|
|
450
|
-
manifest: Manifest | undefined;
|
|
451
|
-
serializer: StartSerializer;
|
|
452
|
-
};
|
|
453
|
-
serverSsr?: ServerSrr;
|
|
454
|
-
basepath: string;
|
|
455
|
-
routesById: RoutesById<TRouteTree>;
|
|
456
|
-
routesByPath: RoutesByPath<TRouteTree>;
|
|
457
|
-
flatRoutes: Array<AnyRoute>;
|
|
458
|
-
parseLocation: ParseLocationFn<TRouteTree>;
|
|
459
|
-
getMatchedRoutes: GetMatchRoutesFn;
|
|
460
|
-
emit: EmitFn;
|
|
461
|
-
load: LoadFn;
|
|
462
|
-
commitLocation: CommitLocationFn;
|
|
463
|
-
buildLocation: BuildLocationFn;
|
|
464
|
-
startTransition: StartTransitionFn;
|
|
465
|
-
subscribe: SubscribeFn;
|
|
466
|
-
matchRoutes: MatchRoutesFn;
|
|
467
|
-
preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
468
|
-
getMatch: GetMatchFn;
|
|
469
|
-
updateMatch: UpdateMatchFn;
|
|
470
|
-
matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
471
|
-
update: UpdateFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
|
|
472
|
-
invalidate: InvalidateFn<Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
|
|
473
|
-
loadRouteChunk: LoadRouteChunkFn;
|
|
474
|
-
resolveRedirect: ResolveRedirect;
|
|
475
|
-
buildRouteTree: () => void;
|
|
476
|
-
clearCache: ClearCacheFn<Router<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
|
|
477
|
-
}
|
|
478
|
-
export type AnyRouterWithContext<TContext> = Router<AnyRouteWithContext<TContext>, any, any, any, any>;
|
|
479
|
-
export type AnyRouter = Router<any, any, any, any, any>;
|
|
434
|
+
export type AnyRouterWithContext<TContext> = RouterCore<AnyRouteWithContext<TContext>, any, any, any, any>;
|
|
435
|
+
export type AnyRouter = RouterCore<any, any, any, any, any>;
|
|
480
436
|
export interface ViewTransitionOptions {
|
|
481
437
|
types: Array<string>;
|
|
482
438
|
}
|
|
@@ -516,4 +472,110 @@ export declare function getLocationChangeInfo(routerState: {
|
|
|
516
472
|
hrefChanged: boolean;
|
|
517
473
|
hashChanged: boolean;
|
|
518
474
|
};
|
|
475
|
+
export type CreateRouterFn = <TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption = 'never', TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>>(options: undefined extends number ? 'strictNullChecks must be enabled in tsconfig.json' : RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
|
|
476
|
+
export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrailingSlashOption extends TrailingSlashOption, in out TDefaultStructuralSharingOption extends boolean, in out TRouterHistory extends RouterHistory = RouterHistory, in out TDehydrated extends Record<string, any> = Record<string, any>> {
|
|
477
|
+
tempLocationKey: string | undefined;
|
|
478
|
+
resetNextScroll: boolean;
|
|
479
|
+
shouldViewTransition?: boolean | ViewTransitionOptions;
|
|
480
|
+
isViewTransitionTypesSupported?: boolean;
|
|
481
|
+
subscribers: Set<RouterListener<RouterEvent>>;
|
|
482
|
+
viewTransitionPromise?: ControlledPromise<true>;
|
|
483
|
+
isScrollRestoring: boolean;
|
|
484
|
+
isScrollRestorationSetup: boolean;
|
|
485
|
+
__store: Store<RouterState<TRouteTree>>;
|
|
486
|
+
options: PickAsRequired<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
487
|
+
history: TRouterHistory;
|
|
488
|
+
latestLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
|
|
489
|
+
basepath: string;
|
|
490
|
+
routeTree: TRouteTree;
|
|
491
|
+
routesById: RoutesById<TRouteTree>;
|
|
492
|
+
routesByPath: RoutesByPath<TRouteTree>;
|
|
493
|
+
flatRoutes: Array<AnyRoute>;
|
|
494
|
+
isServer: boolean;
|
|
495
|
+
pathParamsDecodeCharMap?: Map<string, string>;
|
|
496
|
+
/**
|
|
497
|
+
* @deprecated Use the `createRouter` function instead
|
|
498
|
+
*/
|
|
499
|
+
constructor(options: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>);
|
|
500
|
+
startTransition: StartTransitionFn;
|
|
501
|
+
update: UpdateFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
|
|
502
|
+
get state(): RouterState<TRouteTree, import('./Matches.js').RouteMatch<any, any, any, any, any, any, any>>;
|
|
503
|
+
buildRouteTree: () => void;
|
|
504
|
+
subscribe: SubscribeFn;
|
|
505
|
+
emit: EmitFn;
|
|
506
|
+
parseLocation: ParseLocationFn<TRouteTree>;
|
|
507
|
+
resolvePathWithBase: (from: string, path: string) => string;
|
|
508
|
+
get looseRoutesById(): Record<string, AnyRoute>;
|
|
509
|
+
/**
|
|
510
|
+
@deprecated use the following signature instead
|
|
511
|
+
```ts
|
|
512
|
+
matchRoutes (
|
|
513
|
+
next: ParsedLocation,
|
|
514
|
+
opts?: { preload?: boolean; throwOnError?: boolean },
|
|
515
|
+
): Array<AnyRouteMatch>;
|
|
516
|
+
```
|
|
517
|
+
*/
|
|
518
|
+
matchRoutes: MatchRoutesFn;
|
|
519
|
+
private matchRoutesInternal;
|
|
520
|
+
getMatchedRoutes: GetMatchRoutesFn;
|
|
521
|
+
cancelMatch: (id: string) => void;
|
|
522
|
+
cancelMatches: () => void;
|
|
523
|
+
buildLocation: BuildLocationFn;
|
|
524
|
+
commitLocationPromise: undefined | ControlledPromise<void>;
|
|
525
|
+
commitLocation: CommitLocationFn;
|
|
526
|
+
buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
527
|
+
navigate: NavigateFn;
|
|
528
|
+
latestLoadPromise: undefined | Promise<void>;
|
|
529
|
+
load: LoadFn;
|
|
530
|
+
startViewTransition: (fn: () => Promise<void>) => void;
|
|
531
|
+
updateMatch: UpdateMatchFn;
|
|
532
|
+
getMatch: GetMatchFn;
|
|
533
|
+
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
|
|
534
|
+
location: ParsedLocation;
|
|
535
|
+
matches: Array<AnyRouteMatch>;
|
|
536
|
+
preload?: boolean;
|
|
537
|
+
onReady?: () => Promise<void>;
|
|
538
|
+
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
539
|
+
getMatch?: (matchId: string) => AnyRouteMatch | undefined;
|
|
540
|
+
sync?: boolean;
|
|
541
|
+
}) => Promise<Array<MakeRouteMatch>>;
|
|
542
|
+
invalidate: InvalidateFn<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
|
|
543
|
+
resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
|
|
544
|
+
clearCache: ClearCacheFn<this>;
|
|
545
|
+
clearExpiredCache: () => void;
|
|
546
|
+
loadRouteChunk: (route: AnyRoute) => Promise<void[]>;
|
|
547
|
+
preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
548
|
+
matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
|
|
549
|
+
ssr?: {
|
|
550
|
+
manifest: Manifest | undefined;
|
|
551
|
+
serializer: StartSerializer;
|
|
552
|
+
};
|
|
553
|
+
serverSsr?: {
|
|
554
|
+
injectedHtml: Array<InjectedHtmlEntry>;
|
|
555
|
+
injectHtml: (getHtml: () => string | Promise<string>) => Promise<void>;
|
|
556
|
+
injectScript: (getScript: () => string | Promise<string>, opts?: {
|
|
557
|
+
logScript?: boolean;
|
|
558
|
+
}) => Promise<void>;
|
|
559
|
+
streamValue: (key: string, value: any) => void;
|
|
560
|
+
streamedKeys: Set<string>;
|
|
561
|
+
onMatchSettled: (opts: {
|
|
562
|
+
router: AnyRouter;
|
|
563
|
+
match: AnyRouteMatch;
|
|
564
|
+
}) => any;
|
|
565
|
+
};
|
|
566
|
+
clientSsr?: {
|
|
567
|
+
getStreamedValue: <T>(key: string) => T | undefined;
|
|
568
|
+
};
|
|
569
|
+
_handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, { updateMatch, }?: {
|
|
570
|
+
updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
|
|
571
|
+
}) => void;
|
|
572
|
+
hasNotFoundMatch: () => boolean;
|
|
573
|
+
}
|
|
574
|
+
export declare class SearchParamError extends Error {
|
|
575
|
+
}
|
|
576
|
+
export declare class PathParamError extends Error {
|
|
577
|
+
}
|
|
578
|
+
export declare function lazyFn<T extends Record<string, (...args: Array<any>) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
|
|
579
|
+
export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
|
|
580
|
+
export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent", "notFoundComponent"];
|
|
519
581
|
export {};
|