I've run into an issue where when I run electron-package on my app and run the built app, when I try to access a route besides the default route I get a net::ERR_FILE_NOT_FOUND. I have a login page and when I try clicking log in I get: POST file:///logIn net::ERR_FILE_NOT_FOUND
this is my electron.js
const electron = require('electron');
const { app, BrowserWindow } = electron;
const path = require('path');
const isDev = require('electron-is-dev');
const url = require('url');
let mainWindow = null;
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1024, height: 1024,
autoHideMenuBar: true,
useContentSize: true,
resizable: true,
webPreferences: {
nodeIntegration: true,
devTools: true
}
})
mainWindow.loadURL(`file://${__dirname}/../build/index.html#/`);
mainWindow.on('closed', () => mainWindow = null)
mainWindow.webContents.openDevTools();
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { app.quit() }
})
app.on('activate', () => {
if (mainWindow === null) { createWindow() }
})
package.json
"main": "public/electron.js",
"homepage": "./",
"name": "security-tool",
"version": "0.1.0",
"private": true,
"build": {
"appId": "",
"extends": null,
"files": [
"node_modules/**/*",
"package.json",
"electron.js",
"build/**/*"
],
"directories": {
"buildResources": "assets"
}
},
and just index.js
ReactDOM.render(
<CookiesProvider>
<HashRouter>
<Switch>
<Route path="/home" component={Home} />
<Route path="/projects" component={Projects} />
<Route path="/settings" component={Settings} />
<Route path="/form" component={Form} />
<Route exact path="/" component={Login} />
</Switch>
</HashRouter>,
</CookiesProvider>,
document.getElementById('root')
);
can't show the entire login component but this is the part which has history.push
logIn = async() => {
let results = await logInEndpoint(this.state.Username, this.state.Password);
if(results.result === "Success!") {
const { cookies } = this.props;
cookies.set('userID', results.data[0].USER_ID, { path: '/', maxAge: 3600 });
this.props.history.push('/home');
}
else{
this.invalidCreds(results.result);
}
}