Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

fileRoute.ts

162 lines3.3 KB

1import type { Register } from './router'
2import type {
3 AnyContext,
4 AnyPathParams,
5 AnyRoute,
6 FileBaseRouteOptions,
7 ResolveParams,
8 Route,
9 RouteConstraints,
10 UpdatableRouteOptions,
11} from './route'
12import type { AnyValidator } from './validators'
13​
14export interface FileRouteTypes {
15 fileRoutesByFullPath: any
16 fullPaths: any
17 to: any
18 fileRoutesByTo: any
19 id: any
20 fileRoutesById: any
22​
23export type InferFileRouteTypes<TRouteTree extends AnyRoute> =
24 unknown extends TRouteTree['types']['fileRouteTypes']
25 ? never
26 : TRouteTree['types']['fileRouteTypes'] extends FileRouteTypes
27 ? TRouteTree['types']['fileRouteTypes']
28 : never
29​
30export interface FileRoutesByPath {
31 // '/': {
32 // parentRoute: typeof rootRoute
33 // }
35​
36export interface FileRouteOptions<
37 TRegister,
38 TFilePath extends string,
39 TParentRoute extends AnyRoute,
40 TId extends RouteConstraints['TId'],
41 TPath extends RouteConstraints['TPath'],
42 TFullPath extends RouteConstraints['TFullPath'],
43 TSearchValidator = undefined,
44 TParams = ResolveParams<TPath>,
45 TRouteContextFn = AnyContext,
46 TBeforeLoadFn = AnyContext,
47 TLoaderDeps extends Record<string, any> = {},
48 TLoaderFn = undefined,
49 TSSR = unknown,
50 TServerMiddlewares = unknown,
51 THandlers = undefined,
52> extends FileBaseRouteOptions<
53 TRegister,
54 TParentRoute,
55 TId,
56 TPath,
57 TSearchValidator,
58 TParams,
59 TLoaderDeps,
60 TLoaderFn,
61 AnyContext,
62 TRouteContextFn,
63 TBeforeLoadFn,
64 AnyContext,
65 TSSR,
66 TServerMiddlewares,
67 THandlers
68 >,
69 UpdatableRouteOptions<
70 TParentRoute,
71 TId,
72 TFullPath,
73 TParams,
74 TSearchValidator,
75 TLoaderFn,
76 TLoaderDeps,
77 AnyContext,
78 TRouteContextFn,
79 TBeforeLoadFn
80 > {}
81​
82export type CreateFileRoute<
83 TFilePath extends string,
84 TParentRoute extends AnyRoute,
85 TId extends RouteConstraints['TId'],
86 TPath extends RouteConstraints['TPath'],
87 TFullPath extends RouteConstraints['TFullPath'],
88> = <
89 TRegister = Register,
90 TSearchValidator = undefined,
91 TParams = ResolveParams<TPath>,
92 TRouteContextFn = AnyContext,
93 TBeforeLoadFn = AnyContext,
94 TLoaderDeps extends Record<string, any> = {},
95 TLoaderFn = undefined,
96 TSSR = unknown,
97 TServerMiddlewares = unknown,
98 THandlers = undefined,
99>(
100 options?: FileRouteOptions<
101 TRegister,
102 TFilePath,
103 TParentRoute,
104 TId,
105 TPath,
106 TFullPath,
107 TSearchValidator,
108 TParams,
109 TRouteContextFn,
110 TBeforeLoadFn,
111 TLoaderDeps,
112 TLoaderFn,
113 TSSR,
114 TServerMiddlewares,
115 THandlers
116 >,
117) => Route<
118 TRegister,
119 TParentRoute,
120 TPath,
121 TFullPath,
122 TFilePath,
123 TId,
124 TSearchValidator,
125 TParams,
126 AnyContext,
127 TRouteContextFn,
128 TBeforeLoadFn,
129 TLoaderDeps,
130 TLoaderFn,
131 unknown,
132 unknown,
133 TSSR,
134 TServerMiddlewares,
135 THandlers
137​
138export type LazyRouteOptions = Pick<
139 UpdatableRouteOptions<
140 AnyRoute,
141 string,
142 string,
143 AnyPathParams,
144 AnyValidator,
145 {},
146 AnyContext,
147 AnyContext,
148 AnyContext,
149 AnyContext
150 >,
151 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'
153​
154export interface LazyRoute<in out TRoute extends AnyRoute> {
155 options: {
156 id: string
157 } & LazyRouteOptions
159​
160export type CreateLazyFileRoute<TRoute extends AnyRoute> = (
161 opts: LazyRouteOptions,
162) => LazyRoute<TRoute>