如何正确使用角路由在electronjs中打开新窗口?

时间:2019-10-04 17:00:09

标签: angular electron

我正在尝试使用electronicjs构建有角度的桌面应用程序。使用角度路由打开新窗口时遇到问题。问题是主localhost:4200中所有与* .js相关的文件均未加载,并且新窗口仅显示白页

应用程序在8号角和5号电子上运行。 我尝试用Google搜索,但是我得到的所有示例/视频都是在新窗口中打开外部URL,而不是角路由。

下面是我的index.html:

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Test app</title>
  <base href="">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

</head>

<body>
  <app-root></app-root>
</body>

</html>

下面是app-routing.module:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {CoaComponent} from '../feature/master/coa.component';

const routes: Routes = [
    {
        path: 'master/coa',
        component: CoaComponent
    },
];

@NgModule({
    imports: [RouterModule.forRoot(routes, {useHash: true})],
    exports: [RouterModule],

})
export class AppRoutingModule { }

下面是我在main.ts中打开新窗口的方式

let masterCoaWindow: BrowserWindow = null;
function openMasterCoaWindow() {
    if (!masterCoaWindow) {
        masterCoaWindow = new BrowserWindow({
            width: 800,
            height: 600,
            parent: mainWindow,
            show: false
        });

        masterCoaWindow.loadURL('http://localhost:4200/master/coa');
        masterCoaWindow.once('ready-to-show', () => {
            masterCoaWindow.show();
        });
        masterCoaWindow.webContents.openDevTools();
    } else {
        masterCoaWindow.focus();
    }


    // Emitted when the window is closed.
    masterCoaWindow.on('closed', () => {
        masterCoaWindow = null;
    });
}

这是CoaComponent

import {Component} from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './coa.html',
    styleUrls: ['./coa.component.scss']
})
export class CoaComponent {


}

这是coa.html


<h2>THIS IS COA PAGE</h2>

我希望main.js /其他js的加载方式与localhost:4200相同,但实际结果如下: white page with error

0 个答案:

没有答案