0

I'm following the following demo :

When a user clicks on Home button,is it possible to take the user to a new tab of browser instead of opening the URL in same tab from where the button is clicked? I'm wondering how to modify this line <Button label="Show" icon="pi pi-bars" onClick={(event) => this.menu.toggle(event)}/> to accomplish my goal.

import React, {Component} from 'react';
import {Menu} from 'primereact/menu';

export class MenuDemo extends Component {

    constructor() {
        super();
        this.state = {
            items: [
                {
                    label: 'Options',
                    items: [{label: 'Upload', icon: 'pi pi-fw pi-upload', command:()=>{ window.location.hash="/fileupload"; }},
                            {label: 'Home', icon: 'pi pi-fw pi-home', url: 'http://primetek.com.tr'}]
                }, 
                {
                    label: 'Account',
                    items: [{label: 'Components', icon: 'pi pi-fw pi-cog', command:()=>{ window.location.hash="/"; }},
                            {label: 'Sign Out', icon: 'pi pi-fw pi-power-off'} ]
                }
            ]
        };
    }

    render() {
        return (
            <div>
                <div className="content-section">
                    <div className="feature-intro">
                        <h1>Menu</h1>
                        <p>Menu is a navigation/command component that supports dynamic and static positioning.</p>
                    </div>
                </div>

                <div className="content-section implementation button-demo">
                    <h3 className="first">Basic</h3>
                    <Menu model={this.state.items}/>

                    <h3>Popup</h3>
                    <Menu model={this.state.items} popup={true} ref={el => this.menu = el}/>
                    <Button label="Show" icon="pi pi-bars" onClick={(event) => this.menu.toggle(event)}/>
                </div>

                <MenuDoc/>

            </div>
        )
    }
}
Tan
  • 1,433
  • 5
  • 27
  • 47

1 Answers1

0

You can do something like this in the onclick handler.

window.open(pageurl, "_blank")
Saqib Naseeb
  • 731
  • 1
  • 9
  • 21
  • Isn't it going to break this thing then `{(event) => this.menu.toggle(event)}` ? – Tan Nov 07 '19 at 19:31