When I run my Angular 2 Electron project with ng build or ng serve it works 100% all the routers and everything just work. It was when I started trying to package up my app with electron-packager or builder where I get the routes no longer working. Instead of loading up the Index.html then immediately navigating to my home component it stays at the index. Not even my scss style sheet is working, which should load up immediately.
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>App</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script>window.$ = window.jQuery = require('./public/jquery/dist/jquery.min.js');</script>
<script src="./public/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="./public/bootstrap/dist/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="./public/bootstrap/dist/css/bootstrap-theme.min.css">
</head>
<body>
//The App-root loads from the routes and loads up my home component
<app-root>
Loading...
</app-root>
</body>
</html>
main.js
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({
width: 1024, height: 768,
title:"App"
});
mainWindow.setFullScreen(true);
mainWindow.loadURL(`file://${__dirname}/index.html`);
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function () {
mainWindow = null;
})
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
})
should be:
This works for me, see here