Sibiraj
Sibiraj

Reputation: 4756

How to navigate pages via electron menu - angularjs app

I am new to electron, How to navigate between local pages using electron menu

{
        label: 'Help',
        submenu: [
            {
                label: 'About',
                click(menuItem, browserWindow, event) {
                    browserWindow.loadURL('/about')
                }
            },
            {
                label: package.name + '-' + package.version,
                enabled: false
            }
        ]
    }

How to navigate to a page locally on clicking about menu

Upvotes: 2

Views: 2880

Answers (3)

justDev7a3
justDev7a3

Reputation: 171

When using AngularJS, you can also write it as

label: 'Help',
    submenu: [
        {
            label: 'About',
            click(menuItem, browserWindow, event) {
                browserWindow.loadURL(`file://${__dirname}/app/index.html#/about`)
            }
        },
        ...
    ]

Upvotes: 1

Sibiraj
Sibiraj

Reputation: 4756

One way I found using electron's remote method

main.js (electron file)

window.setMenu(null);

app.js (controller)

const { app, remote } = require('electron')
const { Menu, MenuItem } = remote;

var menuCtrl = function ($scope, $state) {

    const template = [
        {
            label: 'Help',
            submenu: [
                {
                    label: 'About',
                    click() {
                        $state.go('about')
                    }
                }
            ]
        }
    ];

    // Menu
    const menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);

};

menuCtrl.$inject = ['$scope', '$state'];

module.exports = menuCtrl;

Upvotes: 1

Joshua
Joshua

Reputation: 5322

What you've got there is fine except you should put the full url in the .loadURL function like https://stackoverflow.com/tour/

Upvotes: 0

Related Questions