I am using react-route first time.
when i am trying this, it gives me this warning and its not working
"Warning: link is a void element tag and must not have children
or use props.dangerouslySetInnerHTML
. Check the render method of Loginpanel."
my code is like this.
render() {
return (
<div >
<input type="email" />
<input type="password"/><br/>
<link to="Index"> BLOCK
</link>
</div>
)
}
}
and my main main.js is like this
render(
<Router history={hashHistory}>
<Route path="/" component={Loginpanel} >
<Route path="Index" component={App}/>
<Route path="Form" component={Form} />
</Route>
</Router>,
document.getElementById('js-main'));
Thanks in advance.
Void elements should neither have children nor dangerouslySetInnerHTML prop. This rule applies when void elements have either children or dangerouslySetInnerHTML prop. HTML elements such as <area /> , <br /> , and <input /> are void elements which are only self-closing without any content.
To add the link in the menu, use the <NavLink /> component by react-router-dom . The NavLink component provides a declarative way to navigate around the application. It is similar to the Link component, except it can apply an active style to the link if it is active.
In reactjs its Link and not link. Can you try that once?
import{Link} from "react-router-dom"
Change the link
to Link
The first letter is Capitalized.
In complement of Harkirat Saluja answer:
render method example:
render() {
return (
<div>
<Link to="Index">It Link, not link </Link>
</div>
)
}
If you are using react-router version 4 then this is the right way to import Link
import { Link } from 'react-router-dom';
because the React Router project has now been broken up into a couple of different libraries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With