gpt4 book ai didi

reactjs - Electron react 样板 :sub window on clicking a button

转载 作者:行者123 更新时间:2023-12-03 12:21:10 26 4
gpt4 key购买 nike

i have a doubt that how the reactjs file can be loaded into a new window on clicking a button in electron-react-boilerplate.


const handleVideoCall=()=>{
const remote=require('electron').remote;
const BrowserWindow=remote.BrowserWindow;
const win = new BrowserWindow({
height: 600,
width: 800,
});

win.loadFile(fileName);
}

handleVideoCall is the method which is called on clicking the button. FileName is the reactjs file that i needed to open. As there is no documentation from react-electron-boilerplate i was stuck with this. Any help is appreciable.

最佳答案

我得到了答案,我认为这对很多人都有帮助,因为没有关于 Electron react 样板的文档。
使 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`);


}

并在路由器文件上
<Route path="/login" component={Login} />

通过使用此代码,我们可以打开 reactjs 文件并路由到登录。 app.html 是主文件,它在 Electron react 样板代码的 main.dev.js 中加载。散列是打开 reactjs 文件的最简单方法。
由于 Electron 中的 loadURL 只加载 urls 和 htmls 文件,我们无法打开 js 文件。 所以打开主 app.html 并使用路由 进行哈希处理.

关于reactjs - Electron react 样板 :sub window on clicking a button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59563959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com