Reputation: 3
In my simple app,one of my component need the Link component of react-router,like this:
<ul>
<li><Link to="/">javascript</Link></li>
<li><Link to="/">python</Link></li>
<li><Link to="/">java</Link></li>
</ul>
when i import Link in this way:
import { BrowserRouter as Link} from 'react-router-dom'
i got a error:
React.Children.only expected to receive a single React element child
and if i import Link like this :
import { BrowserRouter as Router, Route, Link} from 'react-router-dom'
or this
import { Link} from 'react-router-dom'
that will get nothing errors,anyone can tell me what different in above three ways of import Link component. my react-router-dom version is 4.3.1
Upvotes: 0
Views: 1309
Reputation: 864
The proper way to import the Link component is:
import { Link } from "react-router-dom";
The way you do it: import { BrowserRouter as Link}
is not the correct way, since you are just importing the BrowserRouter component and renaming it to "Link".
Upvotes: 1