@tanstack/react-router 1.9.0 → 1.10.0

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.
@@ -1,6 +1,6 @@
1
1
  import { NoInfer } from '@tanstack/react-store';
2
2
  import { ParsePathParams } from './link';
3
- import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn } from './route';
3
+ import { AnyRoute, ResolveFullPath, ResolveFullSearchSchema, MergeFromFromParent, RouteContext, AnyContext, RouteOptions, UpdatableRouteOptions, Route, RootRouteId, TrimPathLeft, RouteConstraints, ResolveFullSearchSchemaInput, SearchSchemaInput, RouteLoaderFn, AnySearchSchema } from './route';
4
4
  import { Assign, Expand, IsAny } from './utils';
5
5
  export interface FileRoutesByPath {
6
6
  }
@@ -12,10 +12,48 @@ export type RemoveUnderScores<T extends string> = Replace<Replace<TrimRight<Trim
12
12
  type ReplaceFirstOccurrence<T extends string, Search extends string, Replacement extends string> = T extends `${infer Prefix}${Search}${infer Suffix}` ? `${Prefix}${Replacement}${Suffix}` : T;
13
13
  export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : ReplaceFirstOccurrence<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
14
14
  export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}` ? '' : ResolveFilePath<TParentRoute, TFilePath>;
15
+ export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>>(path: TFilePath): <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchemaInput<TParentRoute>, "__TRootSearchSchema__">, TSearchSchemaUsed>>, TFullSearchSchema extends AnySearchSchema = Expand<Assign<Omit<import("./route").InferFullSearchSchema<TParentRoute>, "__TRootSearchSchema__">, TSearchSchema>>, TParams extends Record<string, any> = Expand<Record<TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> extends infer T ? T extends TrimLeft<TrimRight<import("./link").Split<TPath, true>[number], "_">, "_"> ? T extends `$${infer L}` ? L extends "" ? "_splat" : L : never : never : never, string>>, TAllParams extends Record<string, any> = IsAny<TParentRoute["types"]["allParams"], TParams, TParentRoute["types"]["allParams"] & TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}, TParentRoute["types"]["allContext"]>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & UpdatableRouteOptions<TFullSearchSchema, TLoaderData>) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
16
+ /**
17
+ @deprecated It's no longer recommended to use the `FileRoute` class directly.
18
+ Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
19
+ */
15
20
  export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
16
21
  path: TFilePath;
17
22
  constructor(path: TFilePath);
18
- createRoute: <TSearchSchemaInput extends import("./route").AnySearchSchema = {}, TSearchSchema extends import("./route").AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends import("./route").AnySearchSchema = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends import("./route").AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & UpdatableRouteOptions<TFullSearchSchema>) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
23
+ createRoute: <TSearchSchemaInput extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, "__TSearchSchemaInput__"> : TSearchSchema, TFullSearchSchemaInput extends AnySearchSchema = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends Record<string, any> = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends Record<string, any> = MergeFromFromParent<TParentRoute["types"]["allParams"], TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute["types"]["allContext"], {}>, TRouteContext>>, TRouterContext extends AnyContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown, TChildren extends unknown = unknown, TRouteTree extends AnyRoute = AnyRoute>(options?: (Omit<RouteOptions<TParentRoute, string, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute"> & UpdatableRouteOptions<TFullSearchSchema, TLoaderData>) | undefined) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
19
24
  }
25
+ /**
26
+ @deprecated It's recommended not to split loaders into separate files.
27
+ Instead, place the loader function in the the main route file, inside the
28
+ `createFileRoute('/path/to/file)(options)` options.
29
+ */
20
30
  export declare function FileRouteLoader<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(_path: TFilePath): <TLoaderData extends any>(loaderFn: RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], TRoute['types']['routeContext'], TLoaderData>) => RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], TRoute['types']['routeContext'], NoInfer<TLoaderData>>;
31
+ export type LazyRouteOptions = Pick<UpdatableRouteOptions<AnySearchSchema, any>, 'component' | 'errorComponent' | 'pendingComponent'>;
32
+ export declare class LazyRoute<TRoute extends AnyRoute> {
33
+ options: {
34
+ id: string;
35
+ } & LazyRouteOptions;
36
+ constructor(opts: {
37
+ id: string;
38
+ } & LazyRouteOptions);
39
+ useMatch: <TSelected = TRoute["types"]["allContext"]>(opts?: {
40
+ select?: ((s: TRoute['types']['allContext']) => TSelected) | undefined;
41
+ } | undefined) => TSelected;
42
+ useRouteContext: <TSelected = TRoute["types"]["allContext"]>(opts?: {
43
+ select?: ((s: TRoute['types']['allContext']) => TSelected) | undefined;
44
+ } | undefined) => TSelected;
45
+ useSearch: <TSelected = TRoute["types"]["fullSearchSchema"]>(opts?: {
46
+ select?: ((s: TRoute['types']['fullSearchSchema']) => TSelected) | undefined;
47
+ } | undefined) => TSelected;
48
+ useParams: <TSelected = TRoute["types"]["allParams"]>(opts?: {
49
+ select?: ((s: TRoute['types']['allParams']) => TSelected) | undefined;
50
+ } | undefined) => TSelected;
51
+ useLoaderDeps: <TSelected = TRoute["types"]["loaderDeps"]>(opts?: {
52
+ select?: ((s: TRoute['types']['loaderDeps']) => TSelected) | undefined;
53
+ } | undefined) => TSelected;
54
+ useLoaderData: <TSelected = TRoute["types"]["loaderData"]>(opts?: {
55
+ select?: ((s: TRoute['types']['loaderData']) => TSelected) | undefined;
56
+ } | undefined) => TSelected;
57
+ }
58
+ export declare function createLazyFileRoute<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute>;
21
59
  export {};
@@ -1,19 +1,66 @@
1
- import { Route } from "./route.js";
1
+ import { createRoute } from "./route.js";
2
+ import { useMatch, useLoaderDeps, useLoaderData } from "./Matches.js";
3
+ import { useSearch } from "./useSearch.js";
4
+ import { useParams } from "./useParams.js";
5
+ import warning from "tiny-warning";
6
+ function createFileRoute(path) {
7
+ return new FileRoute(path).createRoute;
8
+ }
2
9
  class FileRoute {
3
10
  constructor(path) {
4
11
  this.path = path;
5
12
  this.createRoute = (options) => {
6
- const route = new Route(options);
13
+ warning(
14
+ false,
15
+ "FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."
16
+ );
17
+ const route = createRoute(options);
7
18
  route.isRoot = false;
8
19
  return route;
9
20
  };
10
21
  }
11
22
  }
12
23
  function FileRouteLoader(_path) {
24
+ warning(
25
+ false,
26
+ `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`
27
+ );
13
28
  return (loaderFn) => loaderFn;
14
29
  }
30
+ class LazyRoute {
31
+ constructor(opts) {
32
+ this.useMatch = (opts2) => {
33
+ return useMatch({ select: opts2 == null ? void 0 : opts2.select, from: this.options.id });
34
+ };
35
+ this.useRouteContext = (opts2) => {
36
+ return useMatch({
37
+ from: this.options.id,
38
+ select: (d) => (opts2 == null ? void 0 : opts2.select) ? opts2.select(d.context) : d.context
39
+ });
40
+ };
41
+ this.useSearch = (opts2) => {
42
+ return useSearch({ ...opts2, from: this.options.id });
43
+ };
44
+ this.useParams = (opts2) => {
45
+ return useParams({ ...opts2, from: this.options.id });
46
+ };
47
+ this.useLoaderDeps = (opts2) => {
48
+ return useLoaderDeps({ ...opts2, from: this.options.id });
49
+ };
50
+ this.useLoaderData = (opts2) => {
51
+ return useLoaderData({ ...opts2, from: this.options.id });
52
+ };
53
+ this.options = opts;
54
+ }
55
+ }
56
+ function createLazyFileRoute(id) {
57
+ return (opts) => new LazyRoute({ id, ...opts });
58
+ }
15
59
  export {
16
60
  FileRoute,
17
- FileRouteLoader
61
+ FileRouteLoader,
62
+ LazyRoute,
63
+ createFileRoute,
64
+ createLazyFileRoute
18
65
  };
19
66
  //# sourceMappingURL=fileRoute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { NoInfer } from '@tanstack/react-store'\nimport { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n UpdatableRouteOptions,\n Route,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n ResolveFullSearchSchemaInput,\n SearchSchemaInput,\n LoaderFnContext,\n RouteLoaderFn,\n} from './route'\nimport { Assign, Expand, IsAny } from './utils'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\ntype ReplaceFirstOccurrence<\n T extends string,\n Search extends string,\n Replacement extends string,\n> = T extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replacement}${Suffix}`\n : T\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : ReplaceFirstOccurrence<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchemaUsed extends Record<\n string,\n any\n > = TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : TSearchSchema,\n TFullSearchSchemaInput extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContextReturn extends\n RouteConstraints['TRouteContext'] = RouteContext,\n TRouteContext extends RouteConstraints['TRouteContext'] = [\n TRouteContextReturn,\n ] extends [never]\n ? RouteContext\n : TRouteContextReturn,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options?: Omit<\n RouteOptions<\n TParentRoute,\n string,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TFullSearchSchema>,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TChildren,\n TRouteTree\n > => {\n const route = new Route(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData extends any>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n return (loaderFn) => loaderFn\n}\n"],"names":[],"mappings":";AAqFO,MAAM,UAYX;AAAA,EACA,YAAmB,MAAiB;AAAjB,SAAA,OAAA;AAEnB,SAAA,cAAc,CA4CZ,YA2CG;AACG,YAAA,QAAQ,IAAI,MAAM,OAAc;AACpC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AAAA,EA5F4B;AA8FvC;AAEO,SAAS,gBAId,OAeA;AACA,SAAO,CAAC,aAAa;AACvB;"}
1
+ {"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import { NoInfer } from '@tanstack/react-store'\nimport { ParsePathParams } from './link'\nimport {\n AnyRoute,\n ResolveFullPath,\n ResolveFullSearchSchema,\n MergeFromFromParent,\n RouteContext,\n AnyContext,\n RouteOptions,\n UpdatableRouteOptions,\n Route,\n createRoute,\n RootRouteId,\n TrimPathLeft,\n RouteConstraints,\n ResolveFullSearchSchemaInput,\n SearchSchemaInput,\n LoaderFnContext,\n RouteLoaderFn,\n AnyPathParams,\n AnySearchSchema,\n} from './route'\nimport { Assign, Expand, IsAny } from './utils'\nimport { useMatch, useLoaderDeps, useLoaderData } from './Matches'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport warning from 'tiny-warning'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\ntype Replace<\n S extends string,\n From extends string,\n To extends string,\n> = S extends `${infer Start}${From}${infer Rest}`\n ? `${Start}${To}${Replace<Rest, From, To>}`\n : S\n\nexport type TrimLeft<\n T extends string,\n S extends string,\n> = T extends `${S}${infer U}` ? U : T\n\nexport type TrimRight<\n T extends string,\n S extends string,\n> = T extends `${infer U}${S}` ? U : T\n\nexport type Trim<T extends string, S extends string> = TrimLeft<\n TrimRight<T, S>,\n S\n>\n\nexport type RemoveUnderScores<T extends string> = Replace<\n Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,\n '/_',\n '/'\n>\n\ntype ReplaceFirstOccurrence<\n T extends string,\n Search extends string,\n Replacement extends string,\n> = T extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replacement}${Suffix}`\n : T\n\nexport type ResolveFilePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> = TParentRoute['id'] extends RootRouteId\n ? TrimPathLeft<TFilePath>\n : ReplaceFirstOccurrence<\n TrimPathLeft<TFilePath>,\n TrimPathLeft<TParentRoute['types']['customId']>,\n ''\n >\n\nexport type FileRoutePath<\n TParentRoute extends AnyRoute,\n TFilePath extends string,\n> =\n ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}`\n ? ''\n : ResolveFilePath<TParentRoute, TFilePath>\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n>(path: TFilePath) {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path)\n .createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = TFilePath,\n TPath extends RouteConstraints['TPath'] = FileRoutePath<\n TParentRoute,\n TFilePath\n >,\n TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<\n TParentRoute,\n RemoveUnderScores<TPath>\n >,\n> {\n constructor(public path: TFilePath) {}\n\n createRoute = <\n TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchema extends RouteConstraints['TSearchSchema'] = {},\n TSearchSchemaUsed extends Record<\n string,\n any\n > = TSearchSchemaInput extends SearchSchemaInput\n ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>\n : TSearchSchema,\n TFullSearchSchemaInput extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<\n TParentRoute,\n TSearchSchemaUsed\n >,\n TFullSearchSchema extends\n RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<\n TParentRoute,\n TSearchSchema\n >,\n TParams extends RouteConstraints['TParams'] = Expand<\n Record<ParsePathParams<TPath>, string>\n >,\n TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<\n TParentRoute['types']['allParams'],\n TParams\n >,\n TRouteContextReturn extends\n RouteConstraints['TRouteContext'] = RouteContext,\n TRouteContext extends RouteConstraints['TRouteContext'] = [\n TRouteContextReturn,\n ] extends [never]\n ? RouteContext\n : TRouteContextReturn,\n TAllContext extends Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n > = Expand<\n Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>\n >,\n TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderData extends any = unknown,\n TChildren extends RouteConstraints['TChildren'] = unknown,\n TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,\n >(\n options?: Omit<\n RouteOptions<\n TParentRoute,\n string,\n TPath,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TRouterContext,\n TAllContext,\n TLoaderDeps,\n TLoaderData\n >,\n 'getParentRoute' | 'path' | 'id'\n > &\n UpdatableRouteOptions<TFullSearchSchema, TLoaderData>,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchSchemaInput,\n TSearchSchema,\n TSearchSchemaUsed,\n TFullSearchSchemaInput,\n TFullSearchSchema,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TRouterContext,\n TLoaderDeps,\n TLoaderData,\n TChildren,\n TRouteTree\n > => {\n warning(\n false,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData extends any>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TRoute['types']['routeContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \\`createFileRoute('/path/to/file')(options)\\` options`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<AnySearchSchema, any>,\n 'component' | 'errorComponent' | 'pendingComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n }\n\n useMatch = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath) {\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n"],"names":["opts"],"mappings":";;;;;AA6FO,SAAS,gBAYd,MAAiB;AACV,SAAA,IAAI,UAA0D,IAAI,EACtE;AACL;AAMO,MAAM,UAYX;AAAA,EACA,YAAmB,MAAiB;AAAjB,SAAA,OAAA;AAEnB,SAAA,cAAc,CA4CZ,YA2CG;AACH;AAAA,QACE;AAAA,QACA;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AAAA,EAhG4B;AAkGvC;AAOO,SAAS,gBAId,OAeA;AACA;AAAA,IACE;AAAA,IACA;AAAA,EAAA;AAEF,SAAO,CAAC,aAAa;AACvB;AAOO,MAAM,UAAmC;AAAA,EAK9C,YACE,MAGA;AAIF,SAAA,WAAW,CAA4CA,UAEtC;AACR,aAAA,SAAS,EAAE,QAAQA,SAAA,gBAAAA,MAAM,QAAQ,MAAM,KAAK,QAAQ,GAAA,CAAI;AAAA,IAAA;AAGjE,SAAA,kBAAkB,CAA4CA,UAE7C;AACf,aAAO,SAAS;AAAA,QACd,MAAM,KAAK,QAAQ;AAAA,QACnB,QAAQ,CAAC,OAAYA,SAAA,gBAAAA,MAAM,UAASA,MAAK,OAAO,EAAE,OAAO,IAAI,EAAE;AAAA,MAAA,CAChE;AAAA,IAAA;AAGH,SAAA,YAAY,CAAkDA,UAE7C;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,YAAY,CAA2CA,UAEtC;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAvC9D,SAAK,UAAU;AAAA,EACjB;AAwCF;AAEO,SAAS,oBAGd,IAAe;AACR,SAAA,CAAC,SAA2B,IAAI,UAAkB,EAAE,IAAI,GAAG,MAAM;AAC1E;"}
package/dist/esm/index.js CHANGED
@@ -4,15 +4,15 @@ import { default as default3 } from "tiny-warning";
4
4
  import { Await, useAwaited } from "./awaited.js";
5
5
  import { defer, isDehydratedDeferred } from "./defer.js";
6
6
  import { CatchBoundary, CatchBoundaryImpl, ErrorComponent } from "./CatchBoundary.js";
7
- import { FileRoute, FileRouteLoader } from "./fileRoute.js";
7
+ import { FileRoute, FileRouteLoader, LazyRoute, createFileRoute, createLazyFileRoute } from "./fileRoute.js";
8
8
  import { lazyRouteComponent } from "./lazyRouteComponent.js";
9
9
  import { Link, useLinkProps } from "./link.js";
10
10
  import { Match, MatchRoute, Matches, Outlet, defaultDeserializeError, getRenderedMatches, isServerSideError, matchContext, useLoaderData, useLoaderDeps, useMatch, useMatchRoute, useMatches, useParentMatches } from "./Matches.js";
11
11
  import { cleanPath, interpolatePath, joinPaths, matchByPath, matchPathname, parsePathname, removeBasepath, resolvePath, trimPath, trimPathLeft, trimPathRight } from "./path.js";
12
12
  import { decode, encode } from "./qss.js";
13
13
  import { isRedirect, redirect } from "./redirects.js";
14
- import { NotFoundRoute, RootRoute, Route, RouteApi, createRouteMask, rootRouteId, rootRouteWithContext } from "./route.js";
15
- import { PathParamError, Router, SearchParamError, componentTypes, defaultSerializeError, getInitialRouterState, lazyFn } from "./router.js";
14
+ import { NotFoundRoute, RootRoute, Route, RouteApi, createRootRoute, createRoute, createRouteMask, getRouteApi, rootRouteId, rootRouteWithContext } from "./route.js";
15
+ import { PathParamError, Router, SearchParamError, componentTypes, createRouter, defaultSerializeError, getInitialRouterState, lazyFn } from "./router.js";
16
16
  import { RouterProvider, getRouteMatch } from "./RouterProvider.js";
17
17
  import { ScrollRestoration, useElementScrollRestoration, useScrollRestoration } from "./scroll-restoration.js";
18
18
  import { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith } from "./searchParams.js";
@@ -33,6 +33,7 @@ export {
33
33
  ErrorComponent,
34
34
  FileRoute,
35
35
  FileRouteLoader,
36
+ LazyRoute,
36
37
  Link,
37
38
  Match,
38
39
  MatchRoute,
@@ -50,7 +51,12 @@ export {
50
51
  SearchParamError,
51
52
  cleanPath,
52
53
  componentTypes,
54
+ createFileRoute,
55
+ createLazyFileRoute,
56
+ createRootRoute,
57
+ createRoute,
53
58
  createRouteMask,
59
+ createRouter,
54
60
  decode,
55
61
  deepEqual,
56
62
  defaultDeserializeError,
@@ -63,6 +69,7 @@ export {
63
69
  functionalUpdate,
64
70
  getInitialRouterState,
65
71
  getRenderedMatches,
72
+ getRouteApi,
66
73
  getRouteMatch,
67
74
  interpolatePath,
68
75
  default2 as invariant,
@@ -6,6 +6,7 @@ import { RouteById, RouteIds, RoutePaths } from './routeInfo';
6
6
  import { AnyRouter, RegisteredRouter } from './router';
7
7
  import { Assign, Expand, IsAny, NoInfer, UnionToIntersection } from './utils';
8
8
  import { BuildLocationFn, NavigateFn } from './RouterProvider';
9
+ import { LazyRoute } from '.';
9
10
  export declare const rootRouteId: "__root__";
10
11
  export type RootRouteId = typeof rootRouteId;
11
12
  export type AnyPathParams = {};
@@ -25,7 +26,7 @@ export type RoutePathOptions<TCustomId, TPath> = {
25
26
  id: TCustomId;
26
27
  };
27
28
  export type RoutePathOptionsIntersection<TCustomId, TPath> = UnionToIntersection<RoutePathOptions<TCustomId, TPath>>;
28
- export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends Record<string, any> = {}, TSearchSchemaUsed extends Record<string, any> = {}, TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = RouteContext, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData> & UpdatableRouteOptions<NoInfer<TFullSearchSchema>>;
29
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends Record<string, any> = {}, TSearchSchemaUsed extends Record<string, any> = {}, TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = RouteContext, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData> & UpdatableRouteOptions<NoInfer<TFullSearchSchema>, NoInfer<TLoaderData>>;
29
30
  export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
30
31
  export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends Record<string, any> = {}, TSearchSchemaUsed extends Record<string, any> = {}, TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = RouteContext, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TAllContext extends Record<string, any> = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
31
32
  getParentRoute: () => TParentRoute;
@@ -56,12 +57,13 @@ type BeforeLoadFn<TFullSearchSchema extends Record<string, any>, TParentRoute ex
56
57
  buildLocation: BuildLocationFn<TParentRoute>;
57
58
  cause: 'preload' | 'enter' | 'stay';
58
59
  }) => Promise<TRouteContextReturn> | TRouteContextReturn | void;
59
- export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>> = {
60
+ export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>, TLoaderData extends any> = {
60
61
  caseSensitive?: boolean;
61
62
  wrapInSuspense?: boolean;
62
63
  component?: RouteComponent;
63
64
  errorComponent?: false | null | ErrorRouteComponent;
64
65
  pendingComponent?: RouteComponent;
66
+ lazy?: () => Promise<LazyRoute<any>>;
65
67
  pendingMs?: number;
66
68
  pendingMinMs?: number;
67
69
  staleTime?: number;
@@ -74,7 +76,42 @@ export type UpdatableRouteOptions<TFullSearchSchema extends Record<string, any>>
74
76
  onEnter?: (match: AnyRouteMatch) => void;
75
77
  onStay?: (match: AnyRouteMatch) => void;
76
78
  onLeave?: (match: AnyRouteMatch) => void;
79
+ meta?: (ctx: {
80
+ loaderData: TLoaderData;
81
+ }) => JSX.IntrinsicElements['meta'][];
82
+ links?: () => JSX.IntrinsicElements['link'][];
83
+ scripts?: () => JSX.IntrinsicElements['script'][];
77
84
  };
85
+ export type MetaDescriptor = {
86
+ charSet: 'utf-8';
87
+ } | {
88
+ title: string;
89
+ } | {
90
+ name: string;
91
+ content: string;
92
+ } | {
93
+ property: string;
94
+ content: string;
95
+ } | {
96
+ httpEquiv: string;
97
+ content: string;
98
+ } | {
99
+ 'script:ld+json': LdJsonObject;
100
+ } | {
101
+ tagName: 'meta' | 'link';
102
+ [name: string]: string;
103
+ } | {
104
+ [name: string]: unknown;
105
+ };
106
+ type LdJsonObject = {
107
+ [Key in string]: LdJsonValue;
108
+ } & {
109
+ [Key in string]?: LdJsonValue | undefined;
110
+ };
111
+ type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
112
+ type LdJsonPrimitive = string | number | boolean | null;
113
+ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
114
+ export type RouteLinkEntry = {};
78
115
  export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<TPath, TParams>;
79
116
  export type ParseParamsFn<TPath extends string, TParams> = (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
80
117
  export type ParseParamsObj<TPath extends string, TParams> = {
@@ -134,6 +171,10 @@ export type RouteConstraints = {
134
171
  TChildren: unknown;
135
172
  TRouteTree: AnyRoute;
136
173
  };
174
+ export declare function getRouteApi<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>, TFullSearchSchema extends Record<string, any> = TRoute['types']['fullSearchSchema'], TAllParams extends AnyPathParams = TRoute['types']['allParams'], TAllContext extends Record<string, any> = TRoute['types']['allContext'], TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'], TLoaderData extends any = TRoute['types']['loaderData']>(id: TId): RouteApi<TId, TRoute, TFullSearchSchema, TAllParams, TAllContext, TLoaderDeps, TLoaderData>;
175
+ /**
176
+ * @deprecated Use the `getRouteApi` function instead.
177
+ */
137
178
  export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']>, TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>, TFullSearchSchema extends Record<string, any> = TRoute['types']['fullSearchSchema'], TAllParams extends AnyPathParams = TRoute['types']['allParams'], TAllContext extends Record<string, any> = TRoute['types']['allContext'], TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'], TLoaderData extends any = TRoute['types']['loaderData']> {
138
179
  id: TId;
139
180
  constructor({ id }: {
@@ -158,6 +199,9 @@ export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']
158
199
  select?: ((s: TLoaderData) => TSelected) | undefined;
159
200
  } | undefined) => TSelected;
160
201
  }
202
+ /**
203
+ * @deprecated Use the `createRoute` function instead.
204
+ */
161
205
  export declare class Route<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>, TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {}, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, keyof SearchSchemaInput> : TSearchSchema, TFullSearchSchemaInput extends Record<string, any> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext, TRouteContext extends RouteConstraints['TRouteContext'] = [
162
206
  TRouteContextReturn
163
207
  ] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
@@ -203,7 +247,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
203
247
  updateLoader: <TNewLoaderData extends unknown = unknown>(options: {
204
248
  loader: RouteLoaderFn<TAllParams, TLoaderDeps, TAllContext, TRouteContext, TNewLoaderData>;
205
249
  }) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TNewLoaderData, TChildren, TRouteTree>;
206
- update: (options: UpdatableRouteOptions<TFullSearchSchema>) => this;
250
+ update: (options: UpdatableRouteOptions<TFullSearchSchema, TLoaderData>) => this;
207
251
  useMatch: <TSelected = TAllContext>(opts?: {
208
252
  select?: ((search: TAllContext) => TSelected) | undefined;
209
253
  } | undefined) => TSelected;
@@ -223,11 +267,17 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
223
267
  select?: ((search: TLoaderData) => TSelected) | undefined;
224
268
  } | undefined) => TSelected;
225
269
  }
270
+ 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>, TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {}, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TSearchSchemaUsed extends Record<string, any> = TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, keyof SearchSchemaInput> : TSearchSchema, TFullSearchSchemaInput extends Record<string, any> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext, TRouteContext extends RouteConstraints['TRouteContext'] = [
271
+ TRouteContextReturn
272
+ ] extends [never] ? RouteContext : TRouteContextReturn, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute>(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>): Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree>;
226
273
  export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>;
227
274
  export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchemaInput extends Record<string, any> = RootSearchSchema, TSearchSchema extends Record<string, any> = RootSearchSchema, TSearchSchemaUsed extends Record<string, any> = RootSearchSchema, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TSearchSchemaUsed, TSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, TRouterContext, Assign<TRouterContext, TRouteContext>, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, {}, unknown>;
228
275
  export type RootSearchSchema = {
229
276
  __TRootSearchSchema__: '__TRootSearchSchema__';
230
277
  };
278
+ /**
279
+ * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
280
+ */
231
281
  export declare class RootRoute<TSearchSchemaInput extends Record<string, any> = RootSearchSchema, TSearchSchema extends Record<string, any> = RootSearchSchema, TSearchSchemaUsed extends Record<string, any> = RootSearchSchema, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
232
282
  '/', // TPath
233
283
  '/', // TFullPath
@@ -259,6 +309,19 @@ any> {
259
309
  TRouterContext, Assign<TRouterContext, TRouteContext>, // TAllContext
260
310
  TLoaderDeps, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
261
311
  }
312
+ export declare function createRootRoute<TSearchSchemaInput extends Record<string, any> = RootSearchSchema, TSearchSchema extends Record<string, any> = RootSearchSchema, TSearchSchemaUsed extends Record<string, any> = RootSearchSchema, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = [TRouteContextReturn] extends [never] ? RouteContext : TRouteContextReturn, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown>(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
313
+ RootRouteId, // TCustomId
314
+ '', // TPath
315
+ TSearchSchemaInput, // TSearchSchemaInput
316
+ TSearchSchema, // TSearchSchema
317
+ TSearchSchemaUsed, TSearchSchemaUsed, // TFullSearchSchemaInput
318
+ TSearchSchema, // TFullSearchSchema
319
+ {}, // TParams
320
+ {}, // TAllParams
321
+ TRouteContextReturn, // TRouteContextReturn
322
+ TRouteContext, // TRouteContext
323
+ TRouterContext, Assign<TRouterContext, TRouteContext>, // TAllContext
324
+ TLoaderDeps, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>): RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderData>;
262
325
  export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
263
326
  type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
264
327
  export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
@@ -277,19 +340,28 @@ export type RouteMask<TRouteTree extends AnyRoute> = {
277
340
  export declare function createRouteMask<TRouteTree extends AnyRoute, TFrom extends RoutePaths<TRouteTree>, TTo extends string>(opts: {
278
341
  routeTree: TRouteTree;
279
342
  } & ToSubOptions<TRouteTree, TFrom, TTo>): RouteMask<TRouteTree>;
343
+ /**
344
+ * @deprecated Use `ErrorComponentProps` instead.
345
+ */
280
346
  export type ErrorRouteProps = {
281
347
  error: unknown;
282
348
  info: {
283
349
  componentStack: string;
284
350
  };
285
351
  };
352
+ export type ErrorComponentProps = {
353
+ error: unknown;
354
+ info: {
355
+ componentStack: string;
356
+ };
357
+ };
286
358
  export type ReactNode = any;
287
359
  export type SyncRouteComponent<TProps> = ((props: TProps) => ReactNode) | React.LazyExoticComponent<(props: TProps) => ReactNode>;
288
360
  export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
289
361
  preload?: () => Promise<void>;
290
362
  };
291
363
  export type RouteComponent<TProps = any> = SyncRouteComponent<TProps> & AsyncRouteComponent<TProps>;
292
- export type ErrorRouteComponent = RouteComponent<ErrorRouteProps>;
364
+ export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>;
293
365
  export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TSearchSchemaUsed extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchemaInput extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>> = Expand<Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, TAllContext, TRouterContext, TLoaderDeps, TLoaderData, TChildren, TRouteTree> {
294
366
  constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TFullSearchSchemaInput, TFullSearchSchema, {}, {}, TRouteContextReturn, TRouteContext, TRouterContext, TAllContext, TLoaderDeps, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'>);
295
367
  }
package/dist/esm/route.js CHANGED
@@ -4,6 +4,9 @@ import { trimPath, joinPaths } from "./path.js";
4
4
  import { useParams } from "./useParams.js";
5
5
  import { useSearch } from "./useSearch.js";
6
6
  const rootRouteId = "__root__";
7
+ function getRouteApi(id) {
8
+ return new RouteApi({ id });
9
+ }
7
10
  class RouteApi {
8
11
  constructor({ id }) {
9
12
  this.useMatch = (opts) => {
@@ -110,9 +113,12 @@ class Route {
110
113
  this.$$typeof = Symbol.for("react.memo");
111
114
  }
112
115
  }
116
+ function createRoute(options) {
117
+ return new Route(options);
118
+ }
113
119
  function rootRouteWithContext() {
114
120
  return (options) => {
115
- return new RootRoute(options);
121
+ return createRootRoute(options);
116
122
  };
117
123
  }
118
124
  class RootRoute extends Route {
@@ -120,6 +126,9 @@ class RootRoute extends Route {
120
126
  super(options);
121
127
  }
122
128
  }
129
+ function createRootRoute(options) {
130
+ return new RootRoute(options);
131
+ }
123
132
  function createRouteMask(opts) {
124
133
  return opts;
125
134
  }
@@ -136,7 +145,10 @@ export {
136
145
  RootRoute,
137
146
  Route,
138
147
  RouteApi,
148
+ createRootRoute,
149
+ createRoute,
139
150
  createRouteMask,
151
+ getRouteApi,
140
152
  rootRouteId,
141
153
  rootRouteWithContext
142
154
  };