English 中文(简体)
如何在电子反应中,我可以改变路由 使用 statart 菜单
原标题:How in Electron React I can change Route using standart Menu
I use standart ELectron Menu class and want to change Route in mainWindow: import { app, Menu, shell, BrowserWindow, MenuItemConstructorOptions, } from electron ; export default class MenuBuilder { mainWindow: BrowserWindow; constructor(mainWindow: BrowserWindow) { this.mainWindow = mainWindow; } buildMenu(): Menu { const template = this.buildDefaultTemplate(); const menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); return menu; } buildDefaultTemplate() { const templateDefault = [ { label: CCA , submenu: [ { label: &Buttons , accelerator: Ctrl+B , click: () => { ....some code must go there } } ] } I tried to use next code in Click event ( in code above instead of "....some code must go there"), but it opened new window: const win = new BrowserWindow({ height: 600, width: 800 }); win.loadURL(routes.BUTTONS); But I need to stay in the same window. So I need to change Route, but no information in Menu documentation on how to do this in the correct way.
问题回答
Make sure to expose the necessary methods to the renderer process: preload.js contextBridge.exposeInMainWorld( ipcRenderer , { send: (channel, data) => ipcRenderer.send(channel, data), on: (channel, func) => ipcRenderer.on(channel, (event, ...args) => func(...args)), removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel), }); In the main process, create a function to handle menu clicks and send a message to the renderer process to navigate: main.js const templateDefault = [{ label: CCA , submenu: [{ label: &Buttons , accelerator: Ctrl+B , click: () => { mainWindow.webContents.send( navigate , { path: "/" }); } }] In the renderer process, listen for the navigate event and handle navigation: renderer.js window.ipcRenderer.on( navigate , ({ path }) => { // navigation code goes here; });




相关问题
Delphi 2010 Action Manager & Main Menu Bar

I m trying to use the Action Manager and Action Main Menu Bar in Delphi 2010 an I have no idea how to make this work. I ve tried looking at the examples that come with Delphi 2010 and I can t seem to ...

asp.net (c#) menu/menuItem event/event-handling

Is it possible to use asp.net standard Menu (server-control) for tasks other than navigation? For example: I want to use asp.net menu to add a button control to the asp.net panel (server-control). ...

jQuery javascript menu?

Does anyone know how you create a menu with this rollover effect. Is it using jQuery? I want to create something similar using WordPress as my CMS. Would be great if there is a WordPress plugin? http:/...

jquery conditional logic for currentpage

I m using jQuery for a vertical site navigation menu, all links within site. I have the basic functionality working, but am at a loss as to the correct if-else to accomplish the following: As the ...

Links within and outside List elements not working

I m trying to create a unordered list, with each li element having it s own background image (no text, just image), but I m having trouble (in Firefox at least, it works in Safari) getting the link to ...

Horizontal menu with overflow-x:auto

Is it possible to have a horizontal menu that can scroll overflowed menuitems horizontally, but also display the vertical overflow when a submenu is to appear?

Bash Case menu - dynamic choices

I m not sure what the policy is here on asking followup questions. So please excuse me if i m breaking protocol. Earlier I was constructing a menu in bash ( Here ) And so far I ve got it working ...

热门标签