angular-electron
angular-electron copied to clipboard
Cannot Open new window (not modal)
currently that no way (maybe i don know) to open new window for render angular another page
i am noob, if have a way can teach? Thank you example: window.open('/detail', '_blank', 'top=500,left=200')
Uncaught TypeError: window.require is not a function
at 337 (helper.service.ts:5:19)
at __webpack_require__ (bootstrap:19:1)
at 3972 (home.module.ts:13:24)
at __webpack_require__ (bootstrap:19:1)
at 1075 (helper.service.ts:11:27)
at __webpack_require__ (bootstrap:19:1)
at 5067 (home-routing.module.ts:18:31)
at __webpack_require__ (bootstrap:19:1)
at 2003 (detail.module.ts:13:26)
at __webpack_require__ (bootstrap:19:1)
To navigate / open new pages/windows, you can use RouterLink that comes from Angular Documentation. https://angular.io/tutorial/toh-pt5 you can follow this one.
Does it really work like this?
When I am using <a routerLink="/page2" target="_blank">RouterLink to app</a>
I only receive a blank page in the new electron window because it cannot open the path [...]with error: ERR_FILE_NOT_FOUND
Are there any other ways to solve this? When I use the direct path the new electron window only shows the "Loading..." text from Angular.
Note: I am new to both Electron and Angular, so any help is highly appreciated! :)
Can you please provide your routing module?
Sure:
app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PageNotFoundComponent } from './shared/components';
import { HomeRoutingModule } from './home/home-routing.module';
const routes: Routes = [
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: '**',
component: PageNotFoundComponent
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { useHash: true, relativeLinkResolution: 'legacy' }),
HomeRoutingModule,
Page2RoutingModule
],
exports: [RouterModule]
})
export class AppRoutingModule { }
page2-routing.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
import { Page2Component } from './page2.component';
const routes: Routes = [
{
path: 'page2',
component: Page2Component
}
];
@NgModule({
declarations: [],
imports: [CommonModule, RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class Page2RoutingModule {}
Anyway, for now I used the workaround of just creating a second electron window on launch. If the user closes the second window by accident the application needs a restart. Not ideal, but at least the app is usable now.
win2.loadURL(file://${__dirname}/../dist/index.html#page2
);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
通过设置app/main.ts文件
win.loadURL(url.href);
改为
win.loadURL('http://localhost:4200');
编译的时候将将从链接地址获取页面数据,进行渲染。
这样你在运行程序之前打开angular的服务,就可以正常渲染了。
这也其实也说明了Electron更像是一个浏览器+一些额外平台的api接口。