Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use createElectronRouter with electron-vite #28

Open
dantman opened this issue Nov 23, 2024 · 0 comments
Open

Cannot use createElectronRouter with electron-vite #28

dantman opened this issue Nov 23, 2024 · 0 comments

Comments

@dantman
Copy link

dantman commented Nov 23, 2024

I just tried adding electron-router-dom to a project using electron-vite but ran into a roadblock when trying to refactor the code that calls loadURL/loadFile to use createElectronRouter.

The code in question is written like so, which seems to be effectively what electron-vite's HMR guide suggests.

if (!app.isPackaged && process.env['ELECTRON_RENDERER_URL']) {
    myAppWindow.loadURL(
        `${process.env['ELECTRON_RENDERER_URL']}/src/renderer/main.html`,
    )
} else {
    myAppWindow.loadFile(path.join(__dirname, '../renderer/src/renderer/main.html'))
}

I examined createElectronRouter to see if there's some way I could make it happy, but it appears this cannot be refactored to ELECTRON_RENDERER_URL without some something extra.

  1. const devServerUrl = `http://localhost:${props.port ?? port}`; is hardcoded, so there's no easy way to pass in ELECTRON_RENDERER_URL. This would be simple if devServerUrl were an option.
  2. const URLRoute = createURLRoute(devServerUrl, windowId, { also hardcodes the assumption that loadURL points to the root path. Which won't work if that is not the case. I know electron-router-dom is supposed to be taking care of routing but in this case the multi-page pattern is used because the other html document is a special case like a status window that doesn't fit into being part of the router.
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

No branches or pull requests

1 participant