我怀疑如何在单击 electro-react-boilerplate 中的按钮时将 ReactJS 文件加载到新窗口中。
const handleVideoCall=()=>{
const remote=require('electron').remote;
const BrowserWindow=remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800,
});
win.loadFile(fileName);
}
Run Code Online (Sandbox Code Playgroud)
handleVideoCall 是单击按钮时调用的方法。FileName 是我需要打开的reactjs 文件。由于没有来自反应电子样板的文档,我一直坚持这一点。任何帮助都是值得赞赏的。
我得到了答案,我认为这对很多人都有帮助,因为没有电子反应样板的文档。将nodeIntegration设置为true或预加载js。
const handleVideoCallNew = async number => {
const remote=require('electron').remote;
const BrowserWindow=remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800,
frame:false,
webPreferences: {
nodeIntegration: true,
}
});
win.loadURL(`file://${__dirname}/app.html#/login`);
}
Run Code Online (Sandbox Code Playgroud)
并在路由器文件上
<Route path="/login" component={Login} />
Run Code Online (Sandbox Code Playgroud)
通过使用此代码,我们可以打开reactjs文件并路由到登录。app.html 是主文件,在 electro-react-boilerplate 代码中加载到 main.dev.js 中。哈希是打开reactjs 文件的最简单方法。由于 Electron 中的 loadURL 仅加载 url 和 htmls 文件,因此我们无法打开 js 文件。因此,使用routes打开主app.html和hash。
| 归档时间: |
|
| 查看次数: |
2863 次 |
| 最近记录: |