Skip to content

Electron template opens blank window when run in production mode#424

Merged
aruniverse merged 2 commits intomasterfrom
gytis/fix-blank-electron-screen
Mar 24, 2026
Merged

Electron template opens blank window when run in production mode#424
aruniverse merged 2 commits intomasterfrom
gytis/fix-blank-electron-screen

Conversation

@GytisCepk
Copy link
Copy Markdown
Contributor

Problem

When opening generated electron app in production mode (npm run electron), you were greeted with blank white screen.

Root cause

In production, ElectronHost loads the frontend via electron://frontend/index.html. React Router's BrowserRouter reads window.location.pathname as index.html, which doesn't match any defined route (/, /itwins, /viewer, etc.). Since no route matches, Routes renders nothing — resulting in a blank page.

This only affects production builds. In development mode, the app is served from http://localhost:3000/ where the pathname is /, so routing works correctly.

Fix

Replaced BrowserRouter with HashRouter. HashRouter uses the URL hash fragment (#/) for routing instead of window.location.pathname, making it agnostic to the base URL scheme.

Alternative

Alternative to HashRouter would be MemoryRouter, but I did not find a reason to use it over HashRouter.

More on this: https://stackoverflow.com/questions/36505404/how-to-use-react-router-with-electron/46307415

@aruniverse aruniverse added this pull request to the merge queue Mar 24, 2026
Merged via the queue into master with commit 6711476 Mar 24, 2026
4 checks passed
@aruniverse aruniverse deleted the gytis/fix-blank-electron-screen branch March 24, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page does not load when running electron without vite on windows

2 participants