Reputation: 958
I have a problem like this. I am making a react application. There I have written routs like this.
import React from 'react';
import ReactDOM from 'react-dom';
import {
BrowserRouter as Router,
Route
} from 'react-router-dom'
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import Signup from './components/Signup';
import Officerreg from './components/Officerreg';
import OffenceAdd from './components/OffenceAdd';
import Dofine from './components/Dofine';
import Payfine from './components/Payfine';
import Drivers from './components/Drivers';
import DriversShow from './components/DriversShow';
ReactDOM.render(<Router>
<div>
<Route exact path="/" component={App} />
<Route path="/signup" component={Signup} />
<Route path="/addofficer" component={Officerreg}/>
<Route path="/addoffence" component={OffenceAdd}/>
<Route path="/dofine" component={Dofine}/>
<Route path="/payfine" component={Payfine}/>
<Route path="/drivers" component={Drivers}/>
<Route path="/drivershow/:address" component={DriversShow}/>
</div>
</Router>, document.getElementById('root'));
registerServiceWorker();
I have used those routes in my Header.js file like this.
import React,{ Component } from 'react';
import { Menu } from 'semantic-ui-react';
import { Link } from "react-router-dom";
// import App from '../App';
//
// import './Header.scss';
import web3 from '../ethereum/web3';
import trafficfine from '../ethereum/trafficfine';
import factory from '../ethereum/factory';
export default class Header extends Component {
state = {
activeItem: '',
Officer: false,
driver: false
}
async componentDidMount(){
const accounts = await web3.eth.getAccounts();
const isofficer = await trafficfine.methods.checkOfficer(accounts[0]).call();
const isdriver = await factory.methods.checkDriver(accounts[0]).call();
this.setState({Officer:isofficer,driver:isdriver});
}
handleItemClick = (e, { name }) => this.setState({ activeItem: name })
render(){
const { activeItem,Officer,driver } = this.state;
let show;
return(
<Menu style={{ color:'#ffffff',height:'60px'}}>
<Menu.Item name='browse' active={activeItem === 'browse'} onClick={this.handleItemClick}>
<img src="../favicon.png" style={{maxHeight:'500px'}} alt="logo"></img>
</Menu.Item>
<Menu.Item name='home' active={activeItem === 'home'} onClick={this.handleItemClick}>
<Link to="/">Home</Link>
</Menu.Item>
<Menu.Item name='addofficer' active={activeItem === 'addofficer'} onClick={this.handleItemClick}>
<Link to="/addofficer">Add Officer</Link>
</Menu.Item>
<Menu.Item name='addoffence' active={activeItem === 'addoffence'} onClick={this.handleItemClick}>
<Link to="/addoffence">Add Offence</Link>
</Menu.Item>
<Menu.Item name='dofine' active={activeItem === 'dofine'} onClick={this.handleItemClick} >
<Link to="/dofine">Do Fine</Link>
</Menu.Item>
<Menu.Item name='payfine' active={activeItem === 'payfine'} onClick={this.handleItemClick} >
<Link to="/payfine">Pay Fine</Link>
</Menu.Item>
<Menu.Item name='drivers' active={activeItem === 'drivers'} onClick={this.handleItemClick} >
<Link to="/drivers">Drivers</Link>
</Menu.Item>
<Menu.Menu position='right'>
<Menu.Item name='signup' active={activeItem === 'signup'} onClick={this.handleItemClick}>
<Link to="/signup">Sign Up</Link>
</Menu.Item>
</Menu.Menu>
</Menu>
);
}
};
I have use header in my App.js file like this.
import React, { Component } from 'react';
import './App.css';
import Layout from './components/Layout';
import Header from './components/Header';
import trafficfine from './ethereum/trafficfine';
import { Card, Grid} from 'semantic-ui-react';
// import web3 from './ethereum/web3';
class App extends Component {
state={
numberofDrivers: '',
numberofOfficers: '',
numberofOffencers: '',
fineAmmount: 0
}
async componentDidMount(){
// const accounts = await web3.eth.getAccounts();
const summury = await trafficfine.methods.getSummary().call();
this.setState({numberofDrivers:summury[0],numberofOfficers:summury[1],numberofOffencers:summury[2],fineAmmount:summury[3]});
}
render() {
const{
numberofDrivers,
numberofOffencers,
numberofOfficers,
fineAmmount
}=this.state;
return (
<div className="App">
<Header></Header>
<Layout>
<Grid>
<Grid.Row>
<Grid.Column width={2}></Grid.Column>
<Grid.Column width={12}>
<Grid.Row>
<Card.Group>
<Card style={{background:'#B2EBF2',width:'400px'}}>
<Card.Header>
<Grid>
<Grid.Column width={12}>
<h2 style={{paddingTop:'20px'}}>Number Of Drivers</h2>
</Grid.Column>
<Grid.Row>
<Grid.Column width={8}>
<img src="./driver.png" alt="driver" style={{maxHeight:'100px'}}></img>
</Grid.Column>
<Grid.Column width={4}>
<h2>{numberofDrivers}</h2>
</Grid.Column>
</Grid.Row>
</Grid>
</Card.Header>
<Card.Content>
<Card.Description>
This number of drivers priviladged to use app
</Card.Description>
</Card.Content>
</Card>
<Card style={{background:'#00BCD4',width:'400px'}}>
<Card.Header>
<Grid>
<Grid.Column width={12}>
<h2 style={{paddingTop:'20px'}}>Number Of Officers</h2>
</Grid.Column>
<Grid.Row>
<Grid.Column width={8}>
<img src="./officer.png" alt="driver" style={{maxHeight:'100px'}}></img>
</Grid.Column>
<Grid.Column width={4}>
<h2>{numberofOfficers}</h2>
</Grid.Column>
</Grid.Row>
</Grid>
</Card.Header>
<Card.Content>
<Card.Description>
This is number of Officers authorized to take action
</Card.Description>
</Card.Content>
</Card>
<Card style={{background:'#D1C4E9',width:'400px'}}>
<Card.Header>
<Grid>
<Grid.Column width={14}>
<h2 style={{paddingTop:'20px'}}>Number Of Offencers</h2>
</Grid.Column>
<Grid.Row>
<Grid.Column width={8}>
<img src="./offence.png" alt="driver" style={{maxHeight:'100px'}}></img>
</Grid.Column>
<Grid.Column width={4}>
<h2>{numberofOffencers}</h2>
</Grid.Column>
</Grid.Row>
</Grid>
</Card.Header>
<Card.Content>
<Card.Description>
This Number of offences have been powered
</Card.Description>
</Card.Content>
</Card>
<Card style={{background:'#FFCDD2',width:'400px'}}>
<Card.Header>
<Grid>
<Grid.Column width={12}>
<h2 style={{paddingTop:'20px'}}>Fine Ammount </h2>
</Grid.Column>
<Grid.Row>
<Grid.Column width={8}>
<img src="./fine.png" alt="driver" style={{maxHeight:'100px'}}></img>
</Grid.Column>
<Grid.Column width={4}>
<h2>{fineAmmount}</h2>
</Grid.Column>
</Grid.Row>
</Grid>
</Card.Header>
<Card.Content>
<Card.Description>
This is the Total fine amount
</Card.Description>
</Card.Content>
</Card>
</Card.Group>
</Grid.Row>
</Grid.Column>
</Grid.Row>
</Grid>
</Layout>
</div>
);
}
}
export default App;
When I am routing through the menu it is giving me and warning on the Console like this.
Warning: validateDOMNesting(...): <a> cannot appear as a descendant of <a>.
in a (created by Link)
in Link (at Header.js:61)
in a (created by MenuItem)
in MenuItem (at Header.js:60)
in div (created by Menu)
in Menu (at Header.js:35)
in Header (at Dofine.js:54)
in div (at Dofine.js:53)
in Unknown (created by SideEffect(Component))
in SideEffect(Component) (at Dofine.js:52)
in Dofine (created by Route)
in Route (at src/index.js:24)
in div (at src/index.js:19)
in Router (created by BrowserRouter)
in BrowserRouter (at src/index.js:18)
I searched lot a lot to find a solution for this problem but I was unable to get nothing done by them. If someone can help me to find a solution to this problem it is very grateful.Thank You!
Upvotes: 0
Views: 39
Reputation: 17638
This is not an error but a warning. It occurs because you are trying to render a Link
component from React Router in the Menu.Item
from semantic-ui-react
. They are both compiled into a
in the DOM, so an a
element can't be descendant of another a
element.
Try this in your Menu.Item
s:
<Menu.Item
as={Link}
to="/home"
name="home"
active={activeItem === "home"}
onClick={this.handleItemClick}
>
Home
</Menu.Item>
But, I am not sure about the onClick
part, since you want to use the menu item as a link, it should go to the desired URL when you click. So, what will handleClick
do in this situation?
See the Augmentation part of the documentation. It is on the main page.
Upvotes: 1