Back to previous page : Electron

Asked

Viewed 182 times

0

I’m using Electron to develop an application where your goal is to leave some selected sites there.

Now I’m facing a problem that when I go to a link of one of the options that are in the application I can’t go back to the homepage, where you find the other options.

I’ve tried the following:

const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
let mainWindow;
app.on('ready', () => {
  mainWindow = new BrowserWindow();
  mainWindow.loadURL(path.join('file://', __dirname, 'index.html'));
  setMainMenu();
});

function setMainMenu() {
  const template = [
    {
      label: 'Voltar para o Menu',
      submenu: [
        {
          label: 'Menu Principal',
          accelerator: 'Shift+CmdOrCtrl+H',
          click() {
            win = new BrowserWindow({ width: 1440, height: 800 })
             win.loadFile('index.html')
          }
        }
      ]
    }
  ];
  Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

Only this way it opens a new application and does not go back to the home screen, I wonder if it is possible to make this "back" button, in the native menu of Electron

Image example: Pagina inicial

Indo para um das opções escolhidas

Quando clicado aqui, voltar para o Menu inicial

  • new BrowserWindow will open a new window, if you want to continue on the same screen, I think window.location.href ="/index.html" maybe solve, but I realized that when you open a link, it opens already opens a new window, it would not be correct to just close it?

  • @edsonalves added three images explaining the process that happens, I can’t tell you if closing it would work, but if this is an option, how can I do it ?

  • It goes something like this, I don’t know your version but basically you need to access the remote and get the current window: let w = app.remote.getCurrentWindow(); w.close()

  • is really this way will not work, it closes the application and I need to return to the home page in case the "index.html"

  • Then the other option must serve

  • a doubt, this window.location.href = "/index.html" should go in the right main.js file?

  • In the click, in the same place where you already try to go pro index

  • Maybe it’s right let w = app.remote.getCurrentWindow(); w.location.href ="index.html"

  • it is funny that it gives an error "Cannot read Property getCurrentWindow of Undefined", it seems that it does not know where is the page that should be closed

Show 5 more comments

1 answer

0


I was able to solve it this way:

click(){
 mainWindow.loadFile('index.html')
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.