React-Bootstrap: Customize Navbar's hamburger menu with Font Awesome SVG

扶醉桌前 提交于 2021-01-29 14:43:11

问题


I'm using React-Bootstrap and building a Navbar. I want to replace the React-Bootstrap hamburger menu icon with a Font Awesome hamburger icon.

How do I go about changing the built in hamburger menu? Here is my Navbar:

<Navbar expand="lg">
   <Navbar.Brand href="#home">
      <FontAwesomeIcon icon="gem" color="#20FC8F" size="2x" />
   </Navbar.Brand>
   <Navbar.Toggle aria-controls="basic-navbar-nav"/>
   <Navbar.Collapse id="basic-navbar-nav">
      <Nav className="mr-auto">
         <Nav.Link href="#home">Home</Nav.Link>
         <Nav.Link href="#link">Link</Nav.Link>
      </Nav>
   </Navbar.Collapse>
</Navbar>

I am importing the Font Awesome icon I want to use and displaying it like this:

    <FontAwesomeIcon icon="bars" color="#20FC8F" size="2x" />;

How can I use this in place of the React-Bootstrap toggler?


回答1:


This is how it worked for me. Simply insert <span> element with icon in Navbar.Toggle. Like this:

<Navbar expand="lg">
   <Navbar.Brand href="#home">
      <FontAwesomeIcon icon="gem" color="#20FC8F" size="2x" />
   </Navbar.Brand>
   <Navbar.Toggle aria-controls="basic-navbar-nav">
    <span>
      <FontAwesomeIcon
        icon="bars" color="#20FC8F" size="2x"
      />
    </span>
  </Navbar.Toggle>
   <Navbar.Collapse id="basic-navbar-nav">
      <Nav className="mr-auto">
         <Nav.Link href="#home">Home</Nav.Link>
         <Nav.Link href="#link">Link</Nav.Link>
      </Nav>
   </Navbar.Collapse>
</Navbar>

You can actually omit <span> all whatsoever and it still works.



来源:https://stackoverflow.com/questions/58208067/react-bootstrap-customize-navbars-hamburger-menu-with-font-awesome-svg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!