Electron 如何在各种 .html 文件之间重定向用户
Electron how to redirect users between various .html files
我想尝试将用户从“home.html”重定向到“dashboard.html”。我到处搜索,但我还没有找到答案。
使用 BrowserWindow module, you would have used the method win.loadFile(filePath[, options]) 创建 window 以加载 html 文件时。
一旦更改页面的逻辑成功,您需要做的就是使用新文件的路径再次执行 win.loadFile(filePath[, options]) 行代码。
As win.loadFile(filePath[, options]) returns a promise, let's add a .then()
statement as well (though not requried).
main.js
(主线程)
const electronApp = require('electron').app;
const electronBrowserWindow = require('electron').BrowserWindow;
const nodePath = require("path");
let window;
function createWindow() {
const window = new electronBrowserWindow({
x: 0,
y: 0,
width: 800,
height: 600,
show: false,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: nodePath.join(__dirname, 'preload.js')
}
});
window.loadFile('home.html')
.then(() => { window.show(); });
return window;
}
electronApp.on('ready', () => {
window = createWindow();
});
// Run when logic to change to dashboard is successful.
function showDashboard() {
window.loadFile('dashboard.html')
.then(() => { window.show(); })
}
我想尝试将用户从“home.html”重定向到“dashboard.html”。我到处搜索,但我还没有找到答案。
使用 BrowserWindow module, you would have used the method win.loadFile(filePath[, options]) 创建 window 以加载 html 文件时。
一旦更改页面的逻辑成功,您需要做的就是使用新文件的路径再次执行 win.loadFile(filePath[, options]) 行代码。
As win.loadFile(filePath[, options]) returns a promise, let's add a
.then()
statement as well (though not requried).
main.js
(主线程)
const electronApp = require('electron').app;
const electronBrowserWindow = require('electron').BrowserWindow;
const nodePath = require("path");
let window;
function createWindow() {
const window = new electronBrowserWindow({
x: 0,
y: 0,
width: 800,
height: 600,
show: false,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: nodePath.join(__dirname, 'preload.js')
}
});
window.loadFile('home.html')
.then(() => { window.show(); });
return window;
}
electronApp.on('ready', () => {
window = createWindow();
});
// Run when logic to change to dashboard is successful.
function showDashboard() {
window.loadFile('dashboard.html')
.then(() => { window.show(); })
}