How to Load Angular 2+ Routes in a New BrowserWindow (Electron)?

Without seeing your code and Angular setup it's tricky to know why its not working. You should however be using the node.js path and url modules to build your url.

At a guess, I would say that you need to load your base html file and the hash should be the route you're wanting to load:

const path = require('path');
const url = require('url');

window.loadURL(url.format({
  pathname: path.join(__dirname, './index.html'),
  protocol: 'file:',
  slashes: true,
  hash: '/contact'
}));

Which would give something like:

file:///full-path/to-your/app-root/index.html#/contact"

That means your last example was the closest but manually building the url yourself means that it was not valid:

secondWindow.loadURL('file:' + __dirname + 'dist/index.html#/contact');


In addition to the currently accepted answer, I also needed to turn on useHash in AppRoutingModule.

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: true })],
  exports: [RouterModule]
})