@@ -50,6 +50,7 @@ function createTemplateFile(
5050 templateDir : string ,
5151 file : string ,
5252 targetFileName ?: string ,
53+ extraTemplateValues ?: Record < string , any > ,
5354 ) {
5455 const templateValues = {
5556 packageManager : options . packageManager ,
@@ -68,6 +69,7 @@ function createTemplateFile(
6869 { } ,
6970 ) ,
7071 addOns : options . chosenAddOns ,
72+ ...extraTemplateValues ,
7173 }
7274
7375 const template = await readFile ( resolve ( templateDir , file ) , 'utf-8' )
@@ -300,11 +302,6 @@ export async function createApp(options: Required<Options>) {
300302
301303 // Setup the app component. There are four variations, typescript/javascript and tailwind/non-tailwind.
302304 if ( options . mode === FILE_ROUTER ) {
303- await templateFile (
304- templateDirRouter ,
305- './src/components/Header.tsx.ejs' ,
306- './src/components/Header.tsx' ,
307- )
308305 await templateFile (
309306 templateDirRouter ,
310307 './src/routes/__root.tsx.ejs' ,
@@ -330,19 +327,6 @@ export async function createApp(options: Required<Options>) {
330327 }
331328 }
332329
333- // Create the main entry point
334- if ( ! isAddOnEnabled ( 'start' ) ) {
335- if ( options . typescript ) {
336- await templateFile ( templateDirRouter , './src/main.tsx.ejs' )
337- } else {
338- await templateFile (
339- templateDirRouter ,
340- './src/main.tsx.ejs' ,
341- './src/main.jsx' ,
342- )
343- }
344- }
345-
346330 // Setup the main, reportWebVitals and index.html files
347331 if ( ! isAddOnEnabled ( 'start' ) && options . framework === 'react' ) {
348332 if ( options . typescript ) {
@@ -426,6 +410,54 @@ export async function createApp(options: Required<Options>) {
426410 }
427411 }
428412
413+ const routes : Array < {
414+ path : string
415+ name : string
416+ } > = [ ]
417+ if ( existsSync ( resolve ( targetDir , 'src/routes' ) ) ) {
418+ for ( const file of readdirSync ( resolve ( targetDir , 'src/routes' ) ) ) {
419+ const name = file . replace ( / \. t s x ? | \. j s x ? / , '' )
420+ routes . push ( {
421+ path : `./routes/${ name } ` ,
422+ name : name
423+ . split ( '.' )
424+ . map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
425+ . join ( '' ) ,
426+ } )
427+ }
428+ }
429+
430+ // Create the main entry point
431+ if ( ! isAddOnEnabled ( 'start' ) ) {
432+ if ( options . typescript ) {
433+ await templateFile (
434+ templateDirRouter ,
435+ './src/main.tsx.ejs' ,
436+ './src/main.tsx' ,
437+ {
438+ routes,
439+ } ,
440+ )
441+ } else {
442+ await templateFile (
443+ templateDirRouter ,
444+ './src/main.jsx.ejs' ,
445+ './src/main.jsx' ,
446+ {
447+ routes,
448+ } ,
449+ )
450+ }
451+ }
452+
453+ if ( routes . length > 0 ) {
454+ await templateFile (
455+ templateDirBase ,
456+ './src/components/Header.tsx.ejs' ,
457+ './src/components/Header.tsx' ,
458+ )
459+ }
460+
429461 const warnings : Array < string > = [ ]
430462 for ( const addOn of options . chosenAddOns ) {
431463 if ( addOn . warning ) {
0 commit comments