2017-04-11 47 views
0

我有一個問題,理解角和電子如何一起討論路由。 創建帶有電子主窗口是我想要做的是,使用路由,打開一個新的窗口,這條路線,但返回的錯誤爲以下後:Angular2和電子路由問題

http://localhost:4200/test/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/polyfills.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/scripts.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/styles.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/polyfills.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/scripts.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/styles.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 

電子main.js文件是:

'use strict'; 
const electron = require('electron'); 
// Module to control application life. 
const { app, BrowserWindow, ipcMain } = electron; 

let win; 
let winAttendant; 

ipcMain.on('supportRequest', (e, type, threadObjectId) => { 
    // console.log(args[0]); 
    // e.sender.send('channel1', 'ok got it'); 
    // console.log('1:' + e + '2:' + type + '3:'+ threadObjectId) 
    if (type == 1) { 
     attendantWindow(1, threadObjectId); 
    } else if (type == 2) { 
     attendantWindow(2, threadObjectId); 
    } else { 
     attendantWindow(0); 
    } 

}) 

function attendantWindow(type, threadObjectId) { 
    if (type == 1) { 
     winAttendant = new BrowserWindow({ 
      x: 500, 
      y: 500, 
      minWidth: 300, 
      minHeight: 650 
     }); 

     winAttendant.loadURL('http://localhost:4200/attendantpage/'+ threadObjectId); 

     winAttendant.on('closed',() => { 
      // 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. 
      win = null; 
     }); 
    } else if (type == 2) { 
     console.log('type is: 2 and id: ' + threadObjectId) 
     winAttendant = new BrowserWindow({ 
      x: 500, 
      y: 500, 
      minWidth: 300, 
      minHeight: 650 
     }); 
     console.log('http://localhost:4200/test/'); 
     winAttendant.loadURL('http://localhost:4200/test/'); 

     winAttendant.on('closed',() => { 
      // 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. 
      win = null; 
     }); 
    } else { 
     winAttendant.close(); 
    } 
} 

function createWindow() { 

    let electronScreen = electron.screen; 
    let size = electronScreen.getPrimaryDisplay().workAreaSize; 

    // Create the browser window. 
    win = new BrowserWindow({ 
     minWidth: 900, 
     minHeight: 700, 
     center: true 
    }); 

    let url = 'file://' + __dirname + '/index.html'; 
    let Args = process.argv.slice(1); 

    Args.forEach(function (val) { 
     if (val === "--serve") { 
      url = 'http://localhost:4200' 
     } 
    }); 

    // and load the index.html of the app. 
    win.loadURL(url); 

    // Open the DevTools. 
    // win.webContents.openDevTools(); 

    // Emitted when the window is closed. 
    win.on('closed',() => { 
     // 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. 
     win = 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',() => { 
    // 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',() => { 
    // 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 (win === null) { 
     createWindow(); 
    } 
}); 

在新窗口中打開的組件是使用ng gc test創建的簡單新穎且乾淨的組件。

有人能幫我理解錯誤嗎?

感謝

回答

0

我得到的,因爲試圖處理電子和angular2錯誤的方法這個問題。

爲了應對以正確的方式以及電子和Angular2之間傳遞參數只是使用Angular2 ActivatedRoute + ipcMain從電子:

在電子main.js:

ipcMain.on('chat', (e, args) => { 
    console.log('mainjs threadId: ', args); 
    threadId = args; 
    createChatWindow(threadId); 
}); 

function createChatWindow(threadId) { 
    // Initialize the window to our specified dimensions 
    chatWin = new BrowserWindow({width: 400, height: 500}); 

    // Specify entry point 
    chatWin.loadURL('http://localhost:4200/attendantsupportchat;threadId='+threadId.threadId+';type='+threadId.type); 
    console.log(threadId.threadId); 

    // Remove window once app is closed 
    chatWin.on('closed', function() { 
    win = null; 
    }); 
}; 

在Angular2組件:

import { ActivatedRoute } from '@angular/router'; 

然後在構造函數中初始化如下:

public activatedRoute: ActivatedRoute; 

,並用在需要的地方,像這樣:

this.paramsFromElectron = this.activatedRoute.snapshot.params; 
this.threadId = this.paramsFromElectron.threadId; 
this.threadType = this.paramsFromElectron.type; 

希望能有所幫助

+0

它適用於一個託管的應用程序通過'http://本地主機:4200'但對於當地的一個? – Ismael