【问题标题】:Electron reactjs app show empty page after reloading if user navigate to other route如果用户导航到其他路线,Electron reactjs 应用程序在重新加载后显示空白页面
【发布时间】:2019-11-30 05:45:39
【问题描述】:

我使用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);

【问题讨论】:

    标签: javascript node.js reactjs electron electron-builder


    【解决方案1】:

    我找到了答案。我只需要使用<HashRouter> 而不是<BrowserRouter>

    【讨论】:

    • 可以第一次打开后空白, 从第一次开始空白。
    【解决方案2】:

    重新加载后您的页面为空,因为当您导航到另一个页面时,您更改了 url。所以当你重新加载时,electron 会加载那个 url 而不是 index.html 文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-12
      • 2022-09-29
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2016-12-22
      相关资源
      最近更新 更多