I am using PrimeReact menu to changue routes, the problem that I have is when I run the application, the line "command: this.props.ruta ('Detalle')" run automatically and I can't changue to home. I try to pass parameter to "function handle (route)" for to achieve the change of route but don't work. It don't know if that i did is correct. I hope you can help me. Thanks.
App.js
import './App.css';
import AppMenu from './AppMenu';
import DetalleMeet from './components/detalleMeet.component'
import { MeetList } from './components/meetList.component';
import { Switch, Route, Link } from "react-router-dom";
import { useHistory } from "react-router-dom";
function App() {
const history = useHistory();
function handle(ruta) {
history.push("/" + ruta);
}
return (
<div className="App">
<AppMenu ruta={handle} />
<div className="container mt-3">
<Switch>
<Route exact path={"/meetups"} component={MeetList} />
<Route exact path={"/detalle"} component={DetalleMeet} />
<Route exact path={["/", "/home"]} component={MeetList} />
</Switch>
</div>
</div>
);
}
export default App;
AppMenu.js
import "primeicons/primeicons.css";
import 'primereact/resources/themes/saga-blue/theme.css';
import React from 'react';
import 'primeflex/primeflex.css';
import { Menubar } from 'primereact/menubar';
import { InputText } from 'primereact/inputtext';
import 'primereact/resources/primereact.css';
import 'primeflex/primeflex.css';
export default class AppMenu extends React.Component {
constructor(props) {
super(props);
this.items = [
{
label: 'Home',
icon: 'pi pi-fw pi-file',
command: this.props.ruta('home')
},
{
label: 'Detalle',
icon: 'pi pi-fw pi-pencil',
command: this.props.ruta('Detalle')
},
{
label: 'Users',
icon: 'pi pi-fw pi-user',
},
{
label: 'Events',
icon: 'pi pi-fw pi-calendar',
},
{
label: 'Quit',
icon: 'pi pi-fw pi-power-off'
}
];
}
render(){
const start = <img alt="logo" src="showcase/images/logo.png" onError={(e) => e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="p-mr-2"></img>;
const end = <InputText placeholder="Search" type="text" />;
return (
<div>
<div>
<div className="card">
<Menubar model={this.items} start={start} end={start} />
</div>
</div>
</div>
);
}
}