How in Electron React I can change Route using standart Menu

Viewed 95

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.

0 Answers
Related