Electron template opens blank window when run in production mode#424
Merged
aruniverse merged 2 commits intomasterfrom Mar 24, 2026
Merged
Electron template opens blank window when run in production mode#424aruniverse merged 2 commits intomasterfrom
aruniverse merged 2 commits intomasterfrom
Conversation
aruniverse
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When opening generated electron app in production mode (
npm run electron), you were greeted with blank white screen.Root cause
In production,
ElectronHostloads the frontend viaelectron://frontend/index.html. React Router'sBrowserRouterreadswindow.location.pathnameasindex.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
BrowserRouterwithHashRouter.HashRouteruses the URL hash fragment (#/) for routing instead ofwindow.location.pathname, making it agnostic to the base URL scheme.Alternative
Alternative to
HashRouterwould beMemoryRouter, but I did not find a reason to use it overHashRouter.More on this: https://stackoverflow.com/questions/36505404/how-to-use-react-router-with-electron/46307415