0

I'm trying to make a desktop app using Electron Forge. The app design consists of an index.html page for the home page. The home page contains a button when pressed will cause the app to do some calculation and show the result in another result.html page. However, I can't seem to reference result.html in index.html so that the the packaged app works although it works in dev environment. Can anybody tell me why?

Since someone said I should provide the code. I referenced the result.html page via a button:

<button class="button is-primary" id="scanButton" onclick="window.location.href='result.html'">Scan</button>

Already tried using __dirname but it still says file not found.

2
  • "Can anobody tell me why?" - Pretty sure the answer is no, as you haven't posted any code to create a minimal reproducible example
    – DarkBee
    Commented Jun 4 at 7:22
  • I suppose you need to navigate using hash paths (like #/result.html), but I never tried outside of React so I'm not sure how you should write it.
    – Arkellys
    Commented Jun 4 at 8:37

1 Answer 1

1

In Eectron you cant handle navigation like this , HTML pages in electron is different from traditional web environment.

However you can use ipc.

in your main.js add the result.html using ipcMain

ipcMain.on('navigate-to-result', () => {
  mainWindow.loadFile('result.html');
});

Then you can add an id to the button tag then you have to have script to handel the navigation.

withIn the <script> tag you can execte below to a id you have put in the button tag

addEventListener('click', () => {
      ipcRenderer.send('navigate-to-result');
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.