I am working on an electron project with Create react app. The app works fine in dev. When I package the app with electron-builder, I am able to login to the user account. However, when I logout and redirect to the /signin route, I get a blank screen. When I check the network tab, I get the error that /signin file is not found.
The build section of my package.json
"files": [
"build/**/**/*",
{
"from": "dist/src",
"to": "src",
"filter": [
"**/**/*"
]
},
"node_modules/**/*",
"./main.js"
],
The main.js file
const path = require('path');
const url = require('url');
const { app, BrowserWindow } = require('electron');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
});
const startUrl =
process.env.ELECTRON_START_URL ||
url.format({
pathname: path.join(__dirname, './build/index.html'),
protocol: 'file:',
slashes: true,
});
mainWindow.loadURL(startUrl);
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
require('./src/server/helpers/ipcMainHandler.js');
I am using hashrouter for routing.
What could I be doing wrong?
This was resolved. I figured out the logout method was set to redirect using window.location.href
.
I passed history as an argument to the logout function and used the push method to get it working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.