剛開始看到頁面跳轉,大家一般會想到用 window.location.href = './index.html';
這樣的代碼。結果是可以跳轉,但 DOM事件 基本都會失效。到最后還是使用的 electron 提供的 ipc 接口來創建新的窗口。
2-0、在接收到命令后創建下一個窗口(創建窗口需要時間,期間可能出現空白):
//在main.js中:: const ipc = require('electron').ipcMain; //進行監控,如果有new-window 發送過來,則重新創建一個窗口,文件是list.html ipc.on('new-window',function() { mainWindow.loadURL(url.format({ pathname: path.join(__dirname, '/views/list.html'), protocol: 'file:', slashes: true })) })