I have an ASP.net Core project with React in visual studio. On the nav bar I have a link for twitter.
<ul className="navbar-nav flex-grow">
<NavItem>
<NavLink tag={Link} className="TwitterLogo" to="https://twitter.com/"><img src={SMtwitter}
className="SMicon" alt="TwitterLogo" color="white" /></NavLink>
</NavItem>
The link just adds on the URL to the current page and no delete or rewrite the existing the URL.
NavLinks are react-router specific elements, that should only be used to link to other parts of your app. For external links you should use <a href=""></a>
.
// a normal-looking, HTML-style a tag:
<a href="https://www.example.com">Click Here!</a>
// some kind of Link component, provided by React/Reach Router, Gatsby, etc
<Link to="/example">Click Here!</Link>
The purpose of using react-router-dom
is to navigate to application routes by making changes in the DOM and not reloading the whole page. This scenario is applicable to internal links.
When coming towards external links. It is something that is not the part of our application. We cannot render it in our application context. So, a solution to that is using an a
tag for external links.
<ul className="navbar-nav flex-grow">
<NavItem>
<a className="TwitterLogo" href="https://twitter.com/">
<img src={SMtwitter} className="SMicon" alt="TwitterLogo" color="white" />
</a>
</NavItem>
</ul>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.