Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Router link giving warning " link is a void element tag and must not have `children` or use `props.dangerouslySetInnerHTML`."

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.

like image 617
komal deep singh chahal Avatar asked Aug 06 '16 16:08

komal deep singh chahal


People also ask

Is a void element tag and must neither have children not use dangerouslySetInnerHTML?

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.

How do you define a link in react JS?

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.


4 Answers

In reactjs its Link and not link. Can you try that once?

      import{Link} from "react-router-dom"
like image 143
Harkirat Saluja Avatar answered Oct 06 '22 06:10

Harkirat Saluja


Change the link to Link

The first letter is Capitalized.

like image 21
kfpanda Avatar answered Oct 06 '22 04:10

kfpanda


In complement of Harkirat Saluja answer:

render method example:

render() {

    return (

        <div>
          <Link to="Index">It Link, not link </Link>
       </div>
    )
}
like image 28
Samuel Diogo Avatar answered Oct 06 '22 06:10

Samuel Diogo


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

like image 21
Karim Samir Avatar answered Oct 06 '22 04:10

Karim Samir