Javascript 如果用户导航到其他路线,则重新加载后Electron reactjs应用程序显示空页
我使用Javascript 如果用户导航到其他路线,则重新加载后Electron reactjs应用程序显示空页,javascript,node.js,reactjs,electron,electron-builder,Javascript,Node.js,Reactjs,Electron,Electron Builder,我使用create react app创建项目。我使用路由器的react-router-dom和electron-builder打包我的应用程序 当我第一次运行我的应用程序时,它工作正常,但一旦我重新加载页面,所有内容都变为白色。如果我没有导航到其他路线,应用程序在重新加载后仍然可以工作 下面是我的electron/index.js代码 function createWindow() { mainWindow = new BrowserWindow({ width: 1280,
create react app
创建项目。我使用路由器的react-router-dom
和electron-builder
打包我的应用程序
当我第一次运行我的应用程序时,它工作正常,但一旦我重新加载页面,所有内容都变为白色。如果我没有导航到其他路线,应用程序在重新加载后仍然可以工作
下面是我的electron/index.js代码
function createWindow() {
mainWindow = new BrowserWindow({
width: 1280,
height: 600,
minWidth: 800,
minHeight: 200,
autoHideMenuBar: true,
useContentSize: true,
resizable: true,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadURL(isDev
? 'http://localhost:3000'
: `file://${path.join(__dirname, '../build/index.html')}`);
mainWindow.focus();
mainWindow.on('close', (e) => {
if (willQuitApp) {
/* the user tried to quit the app */
mainWindow = null;
} else {
/* the user only tried to close the window */
e.preventDefault();
mainWindow.hide();
}
});
}
app.on('ready', createWindow);
我找到了答案。我只需要使用
而不是
,我找到了答案。我只需要使用
而不是在重新加载后您会得到一个空页面,因为当您导航到另一个页面时,您会更改url。因此,当您重新加载时,electron将加载该url,而不是重新加载后的index.html
文件,因为当您导航到另一个页面时,您会更改url。因此,当您重新加载时,electron将加载该url,而不是index.html
文件可以第一次打开并变为空白,从第一次开始变为空白。可以第一次打开并变为空白,从第一次开始变为空白。