0

当我使用 ng build 或 ng serve 运行我的 Angular 2 Electron 项目时,它可以 100% 运行所有路由器,并且一切正常。当我开始尝试使用电子打包器或构建器打包我的应用程序时,我的路线不再有效。而不是加载 Index.html 然后立即导航到我的主组件,它停留在索引处。甚至我的 scss 样式表也无法正常工作,应该立即加载。

索引.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();
}
})
4

1 回答 1

1
href="' + document.location + '"

应该:

  href="./" 

这对我有用,看这里

于 2017-07-20T04:43:07.610 回答