我创建了我的React应用程序的构建,并与Electron.js连接。现在如何将我的后端从服务器文件夹与电子连接
我创建了我的React应用程序的构建,并与Electron.js连接。现在如何将我的后端从服务器文件夹与电子连接。
如何将后端添加到Electron .exe。
const { app, BrowserWindow } = require('electron')
const path = require('path')
require('./app');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// win.loadFile('./demo.html')
win.loadFile('./build/index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
这是我的文件夹结构
I create a build of my react app and connected with electron.js. now how to connect my backend from server folder with electron.
How can I add backend to electron .exe
const { app, BrowserWindow } = require('electron')
const path = require('path')
require('./app');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// win.loadFile('./demo.html')
win.loadFile('./build/index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
This is my folder structure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先在前端文件中检查您的路由(例如React中的index.js),如果它是browserrouter,则将其更改为Hashrouter。
现在复制以下代码并将其粘贴到电子主文件
Check your routing first in the frontend file (like an index.js in react) if it is BrowserRouter then change it to HashRouter.
Now copy the below code and paste it to the electron main file