Angular 18 + Electron 打开组件至新窗口时窗口空白问题求助
Angular 18 + Electron 打开组件至新窗口时窗口空白问题求助
我目前在开发一个Angular 18应用,同时用Electron进行打包,现在遇到了一个问题:我想把某个组件在新窗口中打开,但新窗口打开后是空白的,完全加载不出内容。
先给大家看下我的main.js代码:
const { app, BrowserWindow, ipcMain } = require('electron'); const path = require('path'); let mainWindow; // 创建主窗口的函数 async function createWindow() { // 定义主窗口尺寸 mainWindow = new BrowserWindow({ width: 1250, height: 800, frame: true, webPreferences: { nodeIntegration: false, enableRemoteModule: true, contextIsolation: true, preload: path.join(__dirname, 'preload.js') }, }) mainWindow.loadFile('./dist/my-app/browser/index.html'); } app.whenReady().then(()=>{ createWindow(); }); // 创建参数窗口(子窗口)的函数 function createParametersWindow() { let newWindow = new BrowserWindow({ width: 400, height: 300, webPreferences: { contextIsolation: false, nodeIntegration: false, preload: path.join(__dirname, 'preload.js'), }, show: false, }); console.log("Creating parameters window"); newWindow.loadURL('./src/app/parameters/parameters-index/parameters-index.html'); newWindow.on('closed', () => { newWindow = null; }); newWindow.webContents.on('did-finish-load', () => { newWindow.show(); }); }
当前的情况是:我用ng build && electron .命令启动Electron时,主窗口能正常打开并运行,但当我点击触发打开新窗口的按钮后,新窗口确实弹出来了,但里面是空白的。
另外我检查了dist文件夹,里面只有编译后的dist/my-app/browser目录和index.html,完全找不到我要加载的参数组件相关的文件,我不知道这个情况是否正常,也不确定是不是这个导致了空白问题。
有没有大佬能帮忙分析下问题出在哪?万分感谢!
备注:内容来源于stack exchange,提问作者IFrank
相关产品推荐
相关产品推荐

