Blank screen when navigating Angular routes in Electron app

I am currently writing a desktop hybrid application with Electron with AngularJS integration for routing, etc., see the following angular config:

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: '/'
});

});

The application loads fine, and the original "dashboard.html" is entered into the ng-view completely fine.

The problem occurs when I click on a tag to load in another view, for example, site.html. I get a full white screen without errors being output to the console, and no errors coming from node.js.

I am wondering if this is a known issue, or if I did something wrong in my configuration.

+4
source share
2 answers

, .

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

, .

AngularJS not Electron. , #! , hashPrfix app.config,

$locationProvider.hashPrefix('');

Angular Docs .

, - .

+3

.

, , , AngularJS "" -.

, - " " . URL- localhost, -, , AngularJS.

, , .

EDIT: !

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 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 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);
+3

Source: https://habr.com/ru/post/1651326/


All Articles