angular - 打包Angular 2 Electron App时,路线不再起作用

标签 angular electron electron-builder

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

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();
}
})

最佳答案

href="' + document.location + '"

应该:
  href="./" 

这对我有用,请参阅here

关于angular - 打包Angular 2 Electron App时,路线不再起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41476910/

相关文章:

node.js - 在 Angular 5 中使用 electron-builder 构建 Electron 应用程序

typescript - 在 mac 上构建后在 Electron 应用程序中找不到模块

angular - 仅当 Rxjs 轮询上的某些属性发生更改时才调度 NgRx 操作

javascript - 找不到模块 '../dist/ngfactory/src/app/app.server.module.ngf actory'。 Angular 客户端

javascript - 如何从类属性 TypeScript - Angular 中监听值的变化

electron - 如何使用 Electron 存储将对象插入对象数组

javascript - 如何在Windows中的 Electron 应用程序中授予音频权限?

javascript - 属性高度100%在Angular 7 + Electron 4中不起作用

javascript - 如何在 Electron 应用程序中使用音乐元数据摆脱引用错误

google-analytics - 如何在 Electron 中添加Google Analytics