@@ -41,6 +41,7 @@ import {
41
41
import { getTelemetryReporter } from "../utilities/telemetry" ;
42
42
import { ToolKey , ToolsManager } from "./tools" ;
43
43
import { UtilsInterface } from "../common/utils" ;
44
+ import { getAppRoutes } from "../utilities/getFileBasedRoutes" ;
44
45
45
46
const DEVICE_SETTINGS_KEY = "device_settings_v4" ;
46
47
@@ -106,6 +107,11 @@ export class Project
106
107
this . trySelectingInitialDevice ( ) ;
107
108
this . deviceManager . addListener ( "deviceRemoved" , this . removeDeviceListener ) ;
108
109
this . isCachedBuildStale = false ;
110
+ this . dependencyManager . checkProjectUsesExpoRouter ( ) . then ( ( result ) => {
111
+ if ( result ) {
112
+ this . initializeFileBasedRoutes ( ) ;
113
+ }
114
+ } ) ;
109
115
110
116
this . fileWatcher = watchProjectFiles ( ( ) => {
111
117
this . checkIfNativeChanged ( ) ;
@@ -138,6 +144,9 @@ export class Project
138
144
case "navigationChanged" :
139
145
this . eventEmitter . emit ( "navigationChanged" , payload ) ;
140
146
break ;
147
+ case "navigationInit" :
148
+ this . eventEmitter . emit ( "navigationInit" , payload ) ;
149
+ break ;
141
150
case "fastRefreshStarted" :
142
151
this . updateProjectState ( { status : "refreshing" } ) ;
143
152
break ;
@@ -267,6 +276,15 @@ export class Project
267
276
await this . utils . showToast ( "Copied from device clipboard" , 2000 ) ;
268
277
}
269
278
279
+ private async initializeFileBasedRoutes ( ) {
280
+ const routes = await getAppRoutes ( ) ;
281
+ this . devtools . addListener ( ( name ) => {
282
+ if ( name === "RNIDE_appReady" ) {
283
+ this . devtools . send ( "RNIDE_loadFileBasedRoutes" , routes ) ;
284
+ }
285
+ } ) ;
286
+ }
287
+
270
288
onBundleError ( ) : void {
271
289
this . updateProjectState ( { status : "bundleError" } ) ;
272
290
}
@@ -450,28 +468,34 @@ export class Project
450
468
}
451
469
452
470
public async reload ( type : ReloadAction ) : Promise < boolean > {
453
- this . updateProjectState ( { status : "starting" , startupMessage : StartupMessage . Restarting } ) ;
471
+ try {
472
+ this . updateProjectState ( { status : "starting" , startupMessage : StartupMessage . Restarting } ) ;
454
473
455
- getTelemetryReporter ( ) . sendTelemetryEvent ( "url-bar:reload-requested" , {
456
- platform : this . projectState . selectedDevice ?. platform ,
457
- method : type ,
458
- } ) ;
474
+ getTelemetryReporter ( ) . sendTelemetryEvent ( "url-bar:reload-requested" , {
475
+ platform : this . projectState . selectedDevice ?. platform ,
476
+ method : type ,
477
+ } ) ;
459
478
460
- // this action needs to be handled outside of device session as it resets the device session itself
461
- if ( type === "reboot" ) {
462
- const deviceInfo = this . projectState . selectedDevice ! ;
463
- await this . start ( true , false ) ;
464
- await this . selectDevice ( deviceInfo ) ;
465
- return true ;
466
- }
479
+ // this action needs to be handled outside of device session as it resets the device session itself
480
+ if ( type === "reboot" ) {
481
+ const deviceInfo = this . projectState . selectedDevice ! ;
482
+ await this . start ( true , false ) ;
483
+ await this . selectDevice ( deviceInfo ) ;
484
+ return true ;
485
+ }
467
486
468
- const success = ( await this . deviceSession ?. perform ( type ) ) ?? false ;
469
- if ( success ) {
470
- this . updateProjectState ( { status : "running" } ) ;
471
- } else {
472
- window . showErrorMessage ( "Failed to reload, you may try another reload option." , "Dismiss" ) ;
487
+ const success = ( await this . deviceSession ?. perform ( type ) ) ?? false ;
488
+ if ( success ) {
489
+ this . updateProjectState ( { status : "running" } ) ;
490
+ } else {
491
+ window . showErrorMessage ( "Failed to reload, you may try another reload option." , "Dismiss" ) ;
492
+ }
493
+ return success ;
494
+ } finally {
495
+ if ( await this . dependencyManager . checkProjectUsesExpoRouter ( ) ) {
496
+ await this . initializeFileBasedRoutes ( ) ;
497
+ }
473
498
}
474
- return success ;
475
499
}
476
500
477
501
private async start ( restart : boolean , resetMetroCache : boolean ) {
0 commit comments