8

I have an electron app with multiple html files in the root directory.

  • index.html
  • page1.html
  • page.html

I cannot find a way to redirect from index.html to page1.html once Electro has started.

Does anyone know how to do this?

Dany
  • 735
  • 1
  • 8
  • 27
  • 1
    Sometimes people do stupid thins like forgetting a little comma or semi colon. This is one of those occasions. My apologies for bothering you – Dany Nov 08 '15 at 23:01

1 Answers1

15

When your first page is index.html you call that page, when you create your window.

const win = new BrowserWindow(options);
win.loadUrl(`file://${__dirname}/index.html`);

If you want to load another page maybe

win.loadUrl(`file://${__dirname}/page.html`);

could help you.

If the page should be loaded after a user action (e.g. click on a link). You can add the link to your index.hmtl page. Electron works here exactly like a browser.

<a href="page.html">Go to page</a>
apxp
  • 5,240
  • 4
  • 23
  • 43
  • 1
    I have done it with a link, like in your last example and I have a problem. In the new window I cannot use any package with require('packagename');. It says require is not defined. – takluiper Mar 29 '17 at 11:41
  • I believe this is a work around. I will suggest JavaScript libraries for routing such as backbone.js or knockout.js – mumair Dec 26 '17 at 10:50
  • loading a second url with win.loadUrl(`page2.html`); is causing to the browserwindow to flash a white screen while loading the second page, Is there a way to avoid it? – Gatunox Aug 11 '18 at 04:06
  • Apparent, both `win.loadFile("page.html")` and ```win.loadUrl(`file://${remote.app.getAppPath()}/page.html`)``` don't work, but yours does work. – Polv Jan 21 '19 at 06:49