gpt4 book ai didi

angular - location.reload() 和 location.replace(url) 在 Electron 和 Angular 6 中不起作用

转载 作者:行者123 更新时间:2023-12-03 12:21:22 25 4
gpt4 key购买 nike

我使用 Electron 重建一个现成的网络应用程序。 Electron ma​​in.js 很简单:

    // Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')

// 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: 1600,
height: 900
})

// and load the index.html of the app.
mainWindow.loadFile('dist/mysite/index.html')

// 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 macOS 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 macOS 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 (mainWindow === null) {
createWindow()
}
})

当我使用 'electron .' 运行该应用程序时,除了带有 location 的行外,它运行良好。 下面的应用程序代码是登录提交表单操作。 登录后有一行 'location.reload()' 不起作用:

this.http.post(this.url + ':8000/' + 'auth/jwt/create/', this.validateForm.value)
.subscribe((res: any) => {
localStorage.setItem('token', res.token);

// This LINE NOT WORK
location.reload();
// //////

// this.router.navigate([this.router.url]);
// this.router.navigate(['./']);
console.log(location);
}, (err: any) => {
if (err.status === 400) {
this.msg = err.error.non_field_errors[0];
console.log(err);
} else {
this.msg = err;
console.log(err);
}
this.isVisible = true;
});

我尝试了很多方法让网络转到目标网址但都失败了。location.reload() location.replace router.navigate 都不起作用。当我使用“ng serve”并使用 chrome 打开网站时,“location.reload()”没有问题。所以我该怎么做 ? 谢谢。

编辑:location.reload() 执行后,页面变为空白。当 console.log(location) 时,href 是 chrome-error://chromewebdata/

console.log(location)  
Location {replace: ƒ, assign: ƒ, href: "chrome-error://chromewebdata/", ancestorOrigins: DOMStringList, origin: "null", …}

最佳答案

当我向我的 browserView.webContents.on('will-navigate', ...); 引入一个监听器时,它停止为我工作,我正在停止一些事件,页面重新加载被阻止由那个。

关于angular - location.reload() 和 location.replace(url) 在 Electron 和 Angular 6 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53863696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com