I have an Angular 7 application that runs in an Electron window. The Electron process in main.ts must do the following:
main.ts: Show window + load url to Angular app- Angular: does its thing
- Angular: uses ipcRenderer to tell main process that it's temporarily done
main.ts: BrowserWindow.hide()main.ts: Does othermain.ts: BrowserWindow.show()main.ts:mainWindow.webContents.send('route', '/myroute');- Angular:
this.ipcRenderer.on('route', (event: any, route: string) => { this.router.navigateByUrl(route); });
Expected behavior: the window hides, then is shown and shows the new component.
Actual behavior: the window hides, then is shown and shows a partially loaded component followed by the previous route's (e.g. entrypoint) component.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Router, RouterModule, Routes } from '@angular/router';
<route component imports>
const routes: Routes = [
{ path: '', redirectTo: '/entrypoint', pathMatch: 'full' },
{ path: 'entrypoint', component: EntryPointPageComponent },
{ path: 'myroute', component: MyRouteComponent },
{ path: '**', redirectTo: '/entrypoint' }
];
@NgModule({
exports: [ RouterModule ],
imports: [ RouterModule.forRoot(routes, { useHash: true }) ]
})
export class AppRoutingModule {
constructor(private router: Router) {
this.router.events.subscribe((value) => {
console.log(`Router event! ${ typeof value}: ${ value }`);
}, (err) => {
console.log(`Router failure! ${ err }`);
});
}
}
When it's time to go route to /myroute, I see the following events go through, in this order: NavigationStart, RoutesRecognized, GuardsCheckStart, ChildActivationStart, ActivationStart, GuardsCheckEnd, ResolveStart, ResolveEnd, ActivationEnd, ChildActivationEnd, NavigationEnd, Scroll.
Finally, I implemented all of the event lifecycles in MyRouteComponent with console log statements, but none of them get executed.
Any ideas what the issue is that's preventing routing from working successfully?