File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
packages/react-router-dev/typegen Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -105,13 +105,16 @@ export function generateRoutes(ctx: Context): Array<VirtualFile> {
105105 interface Register {
106106 pages: Pages
107107 routeFiles: RouteFiles
108+ routeModules: RouteModules
108109 }
109110 }
110111 ` +
111112 "\n\n" +
112113 Babel . generate ( pagesType ( allPages ) ) . code +
113114 "\n\n" +
114- Babel . generate ( routeFilesType ( { fileToRoutes, routeToPages } ) ) . code ,
115+ Babel . generate ( routeFilesType ( { fileToRoutes, routeToPages } ) ) . code +
116+ "\n\n" +
117+ Babel . generate ( routeModulesType ( ctx ) ) . code ,
115118 } ;
116119
117120 // **/+types/*.ts
@@ -193,6 +196,29 @@ function routeFilesType({
193196 ) ;
194197}
195198
199+ function routeModulesType ( ctx : Context ) {
200+ return t . tsTypeAliasDeclaration (
201+ t . identifier ( "RouteModules" ) ,
202+ null ,
203+ t . tsTypeLiteral (
204+ Object . values ( ctx . config . routes ) . map ( ( route ) =>
205+ t . tsPropertySignature (
206+ t . stringLiteral ( route . id ) ,
207+ t . tsTypeAnnotation (
208+ t . tsTypeQuery (
209+ t . tsImportType (
210+ t . stringLiteral (
211+ `./${ Path . relative ( ctx . rootDirectory , ctx . config . appDirectory ) } /${ route . file } ` ,
212+ ) ,
213+ ) ,
214+ ) ,
215+ ) ,
216+ ) ,
217+ ) ,
218+ ) ,
219+ ) ;
220+ }
221+
196222function isInAppDirectory ( ctx : Context , routeFile : string ) : boolean {
197223 const path = Path . resolve ( ctx . config . appDirectory , routeFile ) ;
198224 return path . startsWith ( ctx . config . appDirectory ) ;
You can’t perform that action at this time.
0 commit comments