在Electron应用程序中导航Angular路线时的空白屏幕

我目前正在编写与Electron AngularJS集成路由等的桌面混合应用程序,请参阅以下angular度configuration:

app.config(function($routeProvider, $locationProvider) { $routeProvider .when('/', { templateUrl: 'partials/dashboard.html', controller: 'dashboardController' }) .when('/sites', { templateUrl: 'partials/sites.html', controller: 'sitesController' }) .when('/sites/:site', { templateUrl: 'partials/site.html', controller: 'siteController' }) .when('/sites/:site/content', { templateUrl: 'partials/site_content.html', controller: 'contentController' }) .when('/sites/:site/content/create', { templateUrl: 'partials/site_content_create.html', controller: 'createController' }) .when('/sites/:site/content/:contentId/edit', { templateUrl: 'partials/site_content_edit.html', controller: 'editController' }) .when('/user', { templateUrl: 'patials/user.html', controller: 'userController' }) .when('/user/edit', { templateUrl: 'partials/user_edit.html', controller: 'userEditController' }) .when('/login', { templateUrl: 'partials/login.html', controller: 'loginController' }) .when('/register', { templateUrl: 'partials/register.html', controller: 'registerController' }); $routeProvider.otherwise({ redirectTo: '/' }); 

});

应用程序加载正常,并且最初的“dashboard.html”被完全正确地注入到ng-view中。

当我点击一个标签来加载另一个视图,例如sites.html时,问题就出现了。 我得到一个完整的白色屏幕,没有错误输出到控制台,也没有任何错误来自node.js本身。

我想知道这是否是一个已知的问题,或者我在configuration中是否做了错误的事情。

最近跑到这里,认为接受的答案太复杂了。 只需修改

 href="#/about" to href="#!/about" 

所有工作都按预期进行。

这是由于AngularJS不是Electron的改变。 另一个解决scheme,如果你不希望包括#! 是通过添加这个修改app.config的hashPrfix

 $locationProvider.hashPrefix(''); 

这里是一个链接到Angular Docs供参考。

希望这节省了别人的头痛。

我终于克服了这个问题。

最后,AngularJS看起来好像只是在Web服务器提供服务的时候才有点“搞笑”。

考虑到这一点,我在电子应用程序的“创build窗口”阶段在特定的端口上实现了一个快速服务器。 然后,我将窗口指向localhost URL,这个URL现在在运行AngularJS的电子应用程序中运行,现在在技术上是一个快速的应用程序。

这让我困惑了一会儿,但是现在看起来它正在工作得很完美,也很快。

编辑:这是代码!

main.js:

 const electron = require('electron'); const server = require("./server"); const sqlite3 = require('sqlite3'); // Module to control application life. const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow; function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({width: 1000, height: 700}); // and load the index.html of the app. //mainWindow.loadURL(`file://${__dirname}/index.html`); mainWindow.loadURL(`http://localhost:3333`); // Open the DevTools. mainWindow.webContents.openDevTools(); // Emitted when the window is closed. mainWindow.on('closed', function () { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. mainWindow = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow); // Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() } }); app.on('activate', function () { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow() } }); process.on('uncaughtException', function (err) { console.log(err); }); // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. 

server.js:

 var path = require('path'); var express = require('express'); var app = express(); app.use(express.static(__dirname)); app.get('/', function (req, res) { res.sendfile(__dirname + 'index.html'); }); app.listen(3333);