@tanstack/router-core 1.132.0-alpha.1 → 1.132.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/cjs/Matches.cjs.map +1 -1
  2. package/dist/cjs/Matches.d.cts +9 -11
  3. package/dist/cjs/config.cjs +10 -0
  4. package/dist/cjs/config.cjs.map +1 -0
  5. package/dist/cjs/config.d.cts +17 -0
  6. package/dist/cjs/fileRoute.d.cts +3 -2
  7. package/dist/cjs/index.cjs +15 -3
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/index.d.cts +11 -4
  10. package/dist/cjs/load-matches.cjs +636 -0
  11. package/dist/cjs/load-matches.cjs.map +1 -0
  12. package/dist/cjs/load-matches.d.cts +16 -0
  13. package/dist/cjs/location.d.cts +38 -0
  14. package/dist/cjs/path.cjs +6 -49
  15. package/dist/cjs/path.cjs.map +1 -1
  16. package/dist/cjs/path.d.cts +3 -6
  17. package/dist/cjs/qss.cjs +19 -19
  18. package/dist/cjs/qss.cjs.map +1 -1
  19. package/dist/cjs/qss.d.cts +6 -4
  20. package/dist/cjs/redirect.cjs +3 -3
  21. package/dist/cjs/redirect.cjs.map +1 -1
  22. package/dist/cjs/rewrite.cjs +63 -0
  23. package/dist/cjs/rewrite.cjs.map +1 -0
  24. package/dist/cjs/rewrite.d.cts +22 -0
  25. package/dist/cjs/route.cjs.map +1 -1
  26. package/dist/cjs/route.d.cts +42 -41
  27. package/dist/cjs/router.cjs +134 -681
  28. package/dist/cjs/router.cjs.map +1 -1
  29. package/dist/cjs/router.d.cts +68 -25
  30. package/dist/cjs/scroll-restoration.cjs +32 -29
  31. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  32. package/dist/cjs/scroll-restoration.d.cts +1 -10
  33. package/dist/cjs/searchParams.cjs +7 -15
  34. package/dist/cjs/searchParams.cjs.map +1 -1
  35. package/dist/cjs/ssr/constants.cjs +5 -0
  36. package/dist/cjs/ssr/constants.cjs.map +1 -0
  37. package/dist/cjs/ssr/constants.d.cts +1 -0
  38. package/dist/cjs/ssr/{seroval-plugins.cjs → serializer/ShallowErrorPlugin.cjs} +2 -2
  39. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -0
  40. package/dist/cjs/ssr/{seroval-plugins.d.cts → serializer/ShallowErrorPlugin.d.cts} +1 -2
  41. package/dist/cjs/ssr/serializer/seroval-plugins.cjs +11 -0
  42. package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -0
  43. package/dist/cjs/ssr/serializer/seroval-plugins.d.cts +2 -0
  44. package/dist/cjs/ssr/serializer/transformer.cjs +52 -0
  45. package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -0
  46. package/dist/cjs/ssr/serializer/transformer.d.cts +56 -0
  47. package/dist/cjs/ssr/server.d.cts +5 -0
  48. package/dist/cjs/ssr/ssr-client.cjs +53 -40
  49. package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
  50. package/dist/cjs/ssr/ssr-client.d.cts +5 -1
  51. package/dist/cjs/ssr/ssr-server.cjs +12 -10
  52. package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
  53. package/dist/cjs/ssr/ssr-server.d.cts +0 -1
  54. package/dist/cjs/ssr/tsrScript.cjs +1 -1
  55. package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
  56. package/dist/cjs/typePrimitives.d.cts +6 -6
  57. package/dist/cjs/utils.cjs +14 -7
  58. package/dist/cjs/utils.cjs.map +1 -1
  59. package/dist/cjs/utils.d.cts +2 -1
  60. package/dist/esm/Matches.d.ts +9 -11
  61. package/dist/esm/Matches.js.map +1 -1
  62. package/dist/esm/config.d.ts +17 -0
  63. package/dist/esm/config.js +10 -0
  64. package/dist/esm/config.js.map +1 -0
  65. package/dist/esm/fileRoute.d.ts +3 -2
  66. package/dist/esm/index.d.ts +11 -4
  67. package/dist/esm/index.js +17 -5
  68. package/dist/esm/index.js.map +1 -1
  69. package/dist/esm/load-matches.d.ts +16 -0
  70. package/dist/esm/load-matches.js +636 -0
  71. package/dist/esm/load-matches.js.map +1 -0
  72. package/dist/esm/location.d.ts +38 -0
  73. package/dist/esm/path.d.ts +3 -6
  74. package/dist/esm/path.js +6 -49
  75. package/dist/esm/path.js.map +1 -1
  76. package/dist/esm/qss.d.ts +6 -4
  77. package/dist/esm/qss.js +19 -19
  78. package/dist/esm/qss.js.map +1 -1
  79. package/dist/esm/redirect.js +3 -3
  80. package/dist/esm/redirect.js.map +1 -1
  81. package/dist/esm/rewrite.d.ts +22 -0
  82. package/dist/esm/rewrite.js +63 -0
  83. package/dist/esm/rewrite.js.map +1 -0
  84. package/dist/esm/route.d.ts +42 -41
  85. package/dist/esm/route.js.map +1 -1
  86. package/dist/esm/router.d.ts +68 -25
  87. package/dist/esm/router.js +136 -683
  88. package/dist/esm/router.js.map +1 -1
  89. package/dist/esm/scroll-restoration.d.ts +1 -10
  90. package/dist/esm/scroll-restoration.js +32 -29
  91. package/dist/esm/scroll-restoration.js.map +1 -1
  92. package/dist/esm/searchParams.js +7 -15
  93. package/dist/esm/searchParams.js.map +1 -1
  94. package/dist/esm/ssr/constants.d.ts +1 -0
  95. package/dist/esm/ssr/constants.js +5 -0
  96. package/dist/esm/ssr/constants.js.map +1 -0
  97. package/dist/esm/ssr/{seroval-plugins.d.ts → serializer/ShallowErrorPlugin.d.ts} +1 -2
  98. package/dist/esm/ssr/{seroval-plugins.js → serializer/ShallowErrorPlugin.js} +2 -2
  99. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -0
  100. package/dist/esm/ssr/serializer/seroval-plugins.d.ts +2 -0
  101. package/dist/esm/ssr/serializer/seroval-plugins.js +11 -0
  102. package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -0
  103. package/dist/esm/ssr/serializer/transformer.d.ts +56 -0
  104. package/dist/esm/ssr/serializer/transformer.js +52 -0
  105. package/dist/esm/ssr/serializer/transformer.js.map +1 -0
  106. package/dist/esm/ssr/server.d.ts +5 -0
  107. package/dist/esm/ssr/ssr-client.d.ts +5 -1
  108. package/dist/esm/ssr/ssr-client.js +53 -40
  109. package/dist/esm/ssr/ssr-client.js.map +1 -1
  110. package/dist/esm/ssr/ssr-server.d.ts +0 -1
  111. package/dist/esm/ssr/ssr-server.js +12 -10
  112. package/dist/esm/ssr/ssr-server.js.map +1 -1
  113. package/dist/esm/ssr/tsrScript.js +1 -1
  114. package/dist/esm/ssr/tsrScript.js.map +1 -1
  115. package/dist/esm/typePrimitives.d.ts +6 -6
  116. package/dist/esm/utils.d.ts +2 -1
  117. package/dist/esm/utils.js +14 -7
  118. package/dist/esm/utils.js.map +1 -1
  119. package/package.json +1 -1
  120. package/src/Matches.ts +18 -10
  121. package/src/config.ts +42 -0
  122. package/src/fileRoute.ts +15 -3
  123. package/src/index.ts +32 -3
  124. package/src/load-matches.ts +955 -0
  125. package/src/location.ts +38 -0
  126. package/src/path.ts +5 -66
  127. package/src/qss.ts +27 -24
  128. package/src/redirect.ts +3 -3
  129. package/src/rewrite.ts +70 -0
  130. package/src/route.ts +146 -35
  131. package/src/router.ts +263 -972
  132. package/src/scroll-restoration.ts +42 -37
  133. package/src/searchParams.ts +8 -19
  134. package/src/ssr/constants.ts +1 -0
  135. package/src/ssr/{seroval-plugins.ts → serializer/ShallowErrorPlugin.ts} +2 -2
  136. package/src/ssr/serializer/seroval-plugins.ts +9 -0
  137. package/src/ssr/serializer/transformer.ts +215 -0
  138. package/src/ssr/server.ts +6 -0
  139. package/src/ssr/ssr-client.ts +72 -44
  140. package/src/ssr/ssr-server.ts +18 -10
  141. package/src/ssr/tsrScript.ts +5 -1
  142. package/src/typePrimitives.ts +6 -6
  143. package/src/utils.ts +21 -10
  144. package/dist/cjs/ssr/seroval-plugins.cjs.map +0 -1
  145. package/dist/esm/ssr/seroval-plugins.js.map +0 -1
@@ -1,18 +1,20 @@
1
1
  import { Store } from '@tanstack/store';
2
+ import { loadRouteChunk } from './load-matches.js';
2
3
  import { ParsePathnameCache } from './path.js';
3
4
  import { SearchParser, SearchSerializer } from './searchParams.js';
4
5
  import { AnyRedirect, ResolvedRedirect } from './redirect.js';
5
6
  import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
6
- import { Awaitable, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
7
+ import { Awaitable, Constrain, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.js';
7
8
  import { ParsedLocation } from './location.js';
8
9
  import { AnyContext, AnyRoute, AnyRouteWithContext, MakeRemountDepsOptionsUnion, RouteMask } from './route.js';
9
10
  import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
10
- import { AnyRouteMatch, MakeRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
11
+ import { AnyRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.js';
11
12
  import { BuildLocationFn, CommitLocationOptions, NavigateFn } from './RouterProvider.js';
12
13
  import { Manifest } from './manifest.js';
13
14
  import { AnySchema } from './validators.js';
14
15
  import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
15
- import { NotFoundError } from './not-found.js';
16
+ import { AnySerializationAdapter, ValidateSerializableInput } from './ssr/serializer/transformer.js';
17
+ import { AnyRouterConfig } from './config.js';
16
18
  export type ControllablePromise<T = any> = Promise<T> & {
17
19
  resolve: (value: T) => void;
18
20
  reject: (value?: any) => void;
@@ -20,6 +22,8 @@ export type ControllablePromise<T = any> = Promise<T> & {
20
22
  export type InjectedHtmlEntry = Promise<string>;
21
23
  export interface DefaultRegister {
22
24
  router: AnyRouter;
25
+ config: AnyRouterConfig;
26
+ ssr: SSROption;
23
27
  }
24
28
  export interface Register extends DefaultRegister {
25
29
  }
@@ -29,7 +33,8 @@ export interface DefaultRouterOptionsExtensions {
29
33
  }
30
34
  export interface RouterOptionsExtensions extends DefaultRouterOptionsExtensions {
31
35
  }
32
- export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated extends Record<string, any> = Record<string, any>> extends RouterOptionsExtensions {
36
+ export type SSROption = boolean | 'data-only';
37
+ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean = false, TRouterHistory extends RouterHistory = RouterHistory, TDehydrated = undefined> extends RouterOptionsExtensions {
33
38
  /**
34
39
  * The history object that will be used to manage the browser history.
35
40
  *
@@ -173,6 +178,18 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
173
178
  /**
174
179
  * The basepath for then entire router. This is useful for mounting a router instance at a subpath.
175
180
  *
181
+ * @deprecated - use `rewrite.input` with the new `rewriteBasepath` utility instead:
182
+ * ```ts
183
+ * const router = createRouter({
184
+ * routeTree,
185
+ * rewrite: rewriteBasepath('/basepath')
186
+ * // Or wrap existing rewrite functionality
187
+ * rewrite: rewriteBasepath('/basepath', {
188
+ * output: ({ url }) => {...},
189
+ * input: ({ url }) => {...},
190
+ * })
191
+ * })
192
+ * ```
176
193
  * @default '/'
177
194
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
178
195
  */
@@ -196,7 +213,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
196
213
  * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#dehydrate-method)
197
214
  * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading#critical-dehydrationhydration)
198
215
  */
199
- dehydrate?: () => Awaitable<TDehydrated>;
216
+ dehydrate?: () => Constrain<TDehydrated, ValidateSerializableInput<Register, TDehydrated>>;
200
217
  /**
201
218
  * A function that will be called when the router is hydrated.
202
219
  *
@@ -262,7 +279,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
262
279
  *
263
280
  * @default true
264
281
  */
265
- defaultSsr?: boolean | 'data-only';
282
+ defaultSsr?: SSROption;
266
283
  search?: {
267
284
  /**
268
285
  * Configures how unknown search params (= not returned by any `validateSearch`) are treated.
@@ -291,7 +308,9 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
291
308
  *
292
309
  * @default false
293
310
  */
294
- scrollRestoration?: boolean;
311
+ scrollRestoration?: boolean | ((opts: {
312
+ location: ParsedLocation;
313
+ }) => boolean);
295
314
  /**
296
315
  * A function that will be called to get the key for the scroll restoration cache.
297
316
  *
@@ -320,7 +339,42 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
320
339
  * @default false
321
340
  */
322
341
  disableGlobalCatchBoundary?: boolean;
342
+ serializationAdapters?: ReadonlyArray<AnySerializationAdapter>;
343
+ /**
344
+ * Configures how the router will rewrite the location between the actual href and the internal href of the router.
345
+ *
346
+ * @default undefined
347
+ * @description You can provide a custom rewrite pair (in/out) or use the utilities like `rewriteBasepath` as a convenience for common use cases, or even do both!
348
+ * This is useful for basepath rewriting, shifting data from the origin to the path (for things like )
349
+ */
350
+ rewrite?: LocationRewrite;
351
+ origin?: string;
323
352
  }
353
+ export type LocationRewrite = {
354
+ /**
355
+ * A function that will be called to rewrite the URL before it is interpreted by the router from the history instance.
356
+ * Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
357
+ *
358
+ * @default undefined
359
+ */
360
+ input?: LocationRewriteFunction;
361
+ /**
362
+ * A function that will be called to rewrite the URL before it is committed to the actual history instance from the router.
363
+ * Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
364
+ *
365
+ * @default undefined
366
+ */
367
+ output?: LocationRewriteFunction;
368
+ };
369
+ /**
370
+ * A function that will be called to rewrite the URL.
371
+ *
372
+ * @param url The URL to rewrite.
373
+ * @returns The rewritten URL (as a URL instance or full href string) or undefined if no rewrite is needed.
374
+ */
375
+ export type LocationRewriteFunction = ({ url, }: {
376
+ url: URL;
377
+ }) => undefined | string | URL;
324
378
  export interface RouterState<in out TRouteTree extends AnyRoute = AnyRoute, in out TRouteMatch = MakeRouteMatchUnion> {
325
379
  status: 'pending' | 'idle';
326
380
  loadedAt: number;
@@ -409,7 +463,7 @@ export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
409
463
  sync?: boolean;
410
464
  forcePending?: boolean;
411
465
  }) => Promise<void>;
412
- export type ParseLocationFn<TRouteTree extends AnyRoute> = (previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>, locationToParse?: HistoryLocation) => ParsedLocation<FullSearchSchema<TRouteTree>>;
466
+ export type ParseLocationFn<TRouteTree extends AnyRoute> = (locationToParse: HistoryLocation, previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>) => ParsedLocation<FullSearchSchema<TRouteTree>>;
413
467
  export type GetMatchRoutesFn = (pathname: string, routePathname: string | undefined) => {
414
468
  matchedRoutes: Array<AnyRoute>;
415
469
  routeParams: Record<string, string>;
@@ -487,6 +541,8 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
487
541
  __store: Store<RouterState<TRouteTree>>;
488
542
  options: PickAsRequired<RouterOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>, 'stringifySearch' | 'parseSearch' | 'context'>;
489
543
  history: TRouterHistory;
544
+ rewrite?: LocationRewrite;
545
+ origin?: string;
490
546
  latestLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
491
547
  basepath: string;
492
548
  routeTree: TRouteTree;
@@ -503,7 +559,8 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
503
559
  isShell(): boolean;
504
560
  isPrerendering(): boolean;
505
561
  update: UpdateFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>;
506
- get state(): RouterState<TRouteTree, import('./Matches.js').RouteMatch<any, any, any, any, any, any, any>>;
562
+ get state(): RouterState<TRouteTree>;
563
+ updateLatestLocation: () => void;
507
564
  buildRouteTree: () => void;
508
565
  subscribe: SubscribeFn;
509
566
  emit: EmitFn;
@@ -528,29 +585,17 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
528
585
  startViewTransition: (fn: () => Promise<void>) => void;
529
586
  updateMatch: UpdateMatchFn;
530
587
  getMatch: GetMatchFn;
531
- loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
532
- location: ParsedLocation;
533
- matches: Array<AnyRouteMatch>;
534
- preload?: boolean;
535
- onReady?: () => Promise<void>;
536
- updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
537
- getMatch?: (matchId: string) => AnyRouteMatch | undefined;
538
- sync?: boolean;
539
- }) => Promise<Array<MakeRouteMatch>>;
540
588
  invalidate: InvalidateFn<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>>;
541
589
  resolveRedirect: (redirect: AnyRedirect) => AnyRedirect;
542
590
  clearCache: ClearCacheFn<this>;
543
591
  clearExpiredCache: () => void;
544
- loadRouteChunk: (route: AnyRoute) => Promise<void[]>;
592
+ loadRouteChunk: typeof loadRouteChunk;
545
593
  preloadRoute: PreloadRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
546
594
  matchRoute: MatchRouteFn<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>;
547
595
  ssr?: {
548
596
  manifest: Manifest | undefined;
549
597
  };
550
598
  serverSsr?: ServerSsr;
551
- _handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError, { updateMatch, }?: {
552
- updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
553
- }) => void;
554
599
  hasNotFoundMatch: () => boolean;
555
600
  }
556
601
  export declare class SearchParamError extends Error {
@@ -559,7 +604,6 @@ export declare class PathParamError extends Error {
559
604
  }
560
605
  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]>>>;
561
606
  export declare function getInitialRouterState(location: ParsedLocation): RouterState<any>;
562
- export declare const componentTypes: readonly ["component", "errorComponent", "pendingComponent", "notFoundComponent"];
563
607
  interface RouteLike {
564
608
  id: string;
565
609
  isRoot?: boolean;
@@ -581,10 +625,9 @@ export declare function processRouteTree<TRouteLike extends RouteLike>({ routeTr
581
625
  routeTree: TRouteLike;
582
626
  initRoute?: (route: TRouteLike, index: number) => void;
583
627
  }): ProcessRouteTreeResult<TRouteLike>;
584
- export declare function getMatchedRoutes<TRouteLike extends RouteLike>({ pathname, routePathname, basepath, caseSensitive, routesByPath, routesById, flatRoutes, parseCache, }: {
628
+ export declare function getMatchedRoutes<TRouteLike extends RouteLike>({ pathname, routePathname, caseSensitive, routesByPath, routesById, flatRoutes, parseCache, }: {
585
629
  pathname: string;
586
630
  routePathname?: string;
587
- basepath: string;
588
631
  caseSensitive?: boolean;
589
632
  routesByPath: Record<string, TRouteLike>;
590
633
  routesById: Record<string, TRouteLike>;