Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

753
Vistas
bootstrap nav link is not working in reactjs

I'm new here also newbie on ReactJS.

Here I created a navbar using bootstrap navbar component in Reactjs.

<Navbar collapseOnSelect expand="lg">
  <Container>
    <Navbar.Brand to={"/"}>Rental</Navbar.Brand>
    <Navbar.Toggle aria-controls="responsive-navbar-nav" />
    <Navbar.Collapse id="responsive-navbar-nav">

    <Nav>
      <Nav.Link to="/" >
         <FontAwesomeIcon 
          icon={faHome} 
       /> Home
     </Nav.Link>
     <Nav.Link to="/login" >
        <FontAwesomeIcon 
        icon={faUser} 
        /> Login/ Registration
     </Nav.Link>
  </Nav>
  </Navbar.Collapse>
 </Container>
</Navbar>

When I go Browser and Check It shows like this:

<a to="/" role="button" class="nav-link" tabindex="0">Home</a>

and the link won't working.

How to fix it?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It looks like you're rendering react-bootstrap's Nav.Link instead of react-router's Link component, so the router is not picking up your route changes.

So importing Link from react router and using it should fix the issue.

import { Link } from 'react-router-dom';

<Nav.Link as={Link} to="/" >
   <FontAwesomeIcon 
      icon={faHome} 
    /> Home
</Nav.Link>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Wrap your code in a Router, make sure that you're doing that inside App or in ReactDOM.render:

import { BrowserRouter } from 'react-router-dom';

ReactDOM.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>, 
  rootElement
  );

You're rendering react-bootstrap's Nav.Link instead of react-router's Link component, so the router is not picking up your route changes.

react-bootstrap provides a render prop in most of its components to specify which component or element we want to render if we don't want the default.

Try to make these changes!

import { Switch, Route, Link } from 'react-router-dom';
<Navbar.Brand as={Link} to="/" >Rental</Navbar.Brand>
<Nav.Link as={Link} to="/" >
    <FontAwesomeIcon icon={faHome}/>
        Home
</Nav.Link>
<Nav.Link as={Link} to="/login" >
    <FontAwesomeIcon icon={faUser}/> 
        Login/ Registration
</Nav.Link>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda