【发布时间】:2018-06-26 18:19:31
【问题描述】:
所以我有一个完成的 Angular 5 应用程序,我想将它转换成一个 Electron 应用程序。除了一件事之外,我已经让应用程序中的所有内容都像在其 Web 应用程序表单中一样工作。我一生都无法弄清楚如何将路由加载到新的 BrowserWindow 中。以下是我正在使用的以及迄今为止我尝试过的:
我用这个加载 mainWindow:
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
我通过 mainWindow 中的 routerLink 成功导航到 Contact 并得到以下结果:
console.log(mainWindow.webContents.getURL()); = file:///C:/Me/Project/dist/contact
现在,我希望通过 mainWindow 在 secondWindow 内打开联系人页面,而不是导航到 mainWindow 内的联系人:
index.html:
<base href="./">
app.routes.ts:
export const routes: Routes = [{
path: 'contact', data: { sectionTitle: 'Contact' },
loadChildren: 'contact/contact.module#ContactModule'
}]
@NgModule({
imports: [
RouterModule.forRoot(routes, { useHash: false })
],
exports: [RouterModule],
declarations: [],
providers: [],
})
export class AppRoutingModule { }
main.js:
secondWindow = new BrowserWindow({
parent: mainWindow,
width: 1024,
height: 768,
frame: false,
minWidth: 1024,
minHeight: 768,
show: false
});
secondWindow.loadURL('file://' + __dirname + 'dist/contact');
secondWindow.show();
这会导致以下错误消息:
Not allowed to load local resource: file:///C:/Me/Project/dist/contact
我没有运气的尝试(也尝试了哈希路由 w/useHash: true):
secondWindow.loadURL('file://' + __dirname + '/dist/contact');
secondWindow.loadURL('file:' + __dirname + '/dist/contact');
secondWindow.loadURL('file:' + __dirname + 'dist/contact');
secondWindow.loadURL('file:' + __dirname + 'dist/index.html#/contact');
有什么想法吗?这是唯一阻碍此 Electron 应用发布的原因。
【问题讨论】: