I’m trying to open a new window with a specific route, but it seems like the route page is not loaded correctly. The new electron window is opened from FrmApprovalMain.js and the new window should be opened with FrmPOdet.js However, when it open, comes up with an error that seems to originate in the calling file (FrmApprovalMain.js) but that has nothing to do with the new window once this is opened… The mainWIndow is fine, but the new opened window throw an error (FrmPOdet.js has only one button on it).
This is the error I get in the new Window (mainWindow no error):
Module../src/FrmApprovalMain.js
G:/Electron/poa/src/FrmApprovalMain.js:10
7 | import NumberFormat from 'react-number-format';
8 | import ModalMessage from './componentAPI/ModalMessage'
9 | import SpinnerCentre from './componentAPI/SpinnerCentre'
> 10 | const electron = window.require('electron');
11 | const ipcRenderer = electron.ipcRenderer;
12 |
13 |
, and these are my statements in the app:
Statement to open a new window (FrmApprovalMain.js)
const electron = window.require('electron');
const ipcRenderer = electron.ipcRenderer;
[...]
openPO(){
console.log("Open new window")
ipcRenderer.send('openNewPO', "S");
console.log("New Window Opened")
}
In electron I have created a new IPC listener where I create the new window:
ipcMain.on('openNewPO',(events,args) =>{
const win = new BrowserWindow({
parent: mainWindow,
height: 600,
width: 800,
show: true,
});
win.removeMenu();
win.loadURL("http://localhost:3000/podet");
});
The router is this
import App from './App';
import FrmPODet from './FrmPODet'
const Router = () => (
<HashRouter>
<Switch>
<Route exact path = "/podet" component = {FrmPODet} />
<Route exact path = "/" component = {App} />
</Switch>
</HashRouter>
);
FrmPODet has one single button