@@ -8,6 +8,10 @@ export function setAppDirectory(directory: string) {
8
8
appDirectory = directory ;
9
9
}
10
10
11
+ /**
12
+ * Provides the absolute path to the app directory, for use within `routes.ts`.
13
+ * This is designed to support resolving file system routes.
14
+ */
11
15
export function getAppDirectory ( ) {
12
16
invariant ( appDirectory ) ;
13
17
return appDirectory ;
@@ -52,10 +56,15 @@ export interface RouteManifest {
52
56
[ routeId : string ] : RouteManifestEntry ;
53
57
}
54
58
59
+ /**
60
+ * Route config to be exported via the `routes` export within `routes.ts`.
61
+ */
55
62
export type RouteConfig = RouteConfigEntry [ ] | Promise < RouteConfigEntry [ ] > ;
56
63
57
64
/**
58
- * A route exported from the routes config file
65
+ * Configuration for an individual route, for use within `routes.ts`. As a
66
+ * convenience, route config entries can be created with the {@link route},
67
+ * {@link index} and {@link layout} helper functions.
59
68
*/
60
69
export interface RouteConfigEntry {
61
70
/**
@@ -90,8 +99,6 @@ export interface RouteConfigEntry {
90
99
children ?: RouteConfigEntry [ ] ;
91
100
}
92
101
93
- type CreateRoutePath = string | null | undefined ;
94
-
95
102
const createConfigRouteOptionKeys = [
96
103
"id" ,
97
104
"index" ,
@@ -101,19 +108,23 @@ type CreateRouteOptions = Pick<
101
108
RouteConfigEntry ,
102
109
( typeof createConfigRouteOptionKeys ) [ number ]
103
110
> ;
111
+ /**
112
+ * Helper function for creating a route config entry, for use within
113
+ * `routes.ts`.
114
+ */
104
115
function createRoute (
105
- path : CreateRoutePath ,
116
+ path : string | null | undefined ,
106
117
file : string ,
107
118
children ?: RouteConfigEntry [ ]
108
119
) : RouteConfigEntry ;
109
120
function createRoute (
110
- path : CreateRoutePath ,
121
+ path : string | null | undefined ,
111
122
file : string ,
112
123
options : CreateRouteOptions ,
113
124
children ?: RouteConfigEntry [ ]
114
125
) : RouteConfigEntry ;
115
126
function createRoute (
116
- path : CreateRoutePath ,
127
+ path : string | null | undefined ,
117
128
file : string ,
118
129
optionsOrChildren : CreateRouteOptions | RouteConfigEntry [ ] | undefined ,
119
130
children ?: RouteConfigEntry [ ]
@@ -141,6 +152,10 @@ type CreateIndexOptions = Pick<
141
152
RouteConfigEntry ,
142
153
( typeof createIndexOptionKeys ) [ number ]
143
154
> ;
155
+ /**
156
+ * Helper function for creating a route config entry for an index route, for use
157
+ * within `routes.ts`.
158
+ */
144
159
function createIndex (
145
160
file : string ,
146
161
options ?: CreateIndexOptions
@@ -159,6 +174,10 @@ type CreateLayoutOptions = Pick<
159
174
RouteConfigEntry ,
160
175
( typeof createLayoutOptionKeys ) [ number ]
161
176
> ;
177
+ /**
178
+ * Helper function for creating a route config entry for a layout route, for use
179
+ * within `routes.ts`.
180
+ */
162
181
function createLayout (
163
182
file : string ,
164
183
children ?: RouteConfigEntry [ ]
@@ -191,19 +210,41 @@ function createLayout(
191
210
export const route = createRoute ;
192
211
export const index = createIndex ;
193
212
export const layout = createLayout ;
194
- type RouteHelpers = {
213
+ /**
214
+ * Creates a set of route config helpers that resolve file paths relative to the
215
+ * given directory, for use within `routes.ts`. This is designed to support
216
+ * splitting route config into multiple files within different directories.
217
+ */
218
+ export function relative ( directory : string ) : {
195
219
route : typeof route ;
196
220
index : typeof index ;
197
221
layout : typeof layout ;
198
- } ;
199
- export function relative ( directory : string ) : RouteHelpers {
222
+ } {
200
223
return {
224
+ /**
225
+ * Helper function for creating a route config entry, for use within
226
+ * `routes.ts`. Note that this helper has been scoped, meaning that file
227
+ * path will be resolved relative to the directory provided to the
228
+ * `relative` call that created this helper.
229
+ */
201
230
route : ( path , file , ...rest ) => {
202
231
return route ( path , resolve ( directory , file ) , ...( rest as any ) ) ;
203
232
} ,
233
+ /**
234
+ * Helper function for creating a route config entry for an index route, for
235
+ * use within `routes.ts`. Note that this helper has been scoped, meaning
236
+ * that file path will be resolved relative to the directory provided to the
237
+ * `relative` call that created this helper.
238
+ */
204
239
index : ( file , ...rest ) => {
205
240
return index ( resolve ( directory , file ) , ...( rest as any ) ) ;
206
241
} ,
242
+ /**
243
+ * Helper function for creating a route config entry for a layout route, for
244
+ * use within `routes.ts`. Note that this helper has been scoped, meaning
245
+ * that file path will be resolved relative to the directory provided to the
246
+ * `relative` call that created this helper.
247
+ */
207
248
layout : ( file , ...rest ) => {
208
249
return layout ( resolve ( directory , file ) , ...( rest as any ) ) ;
209
250
} ,
0 commit comments