React JS Bootstrap Navbar Component Example

Sep 05, 2022 . Admin

Hello Artisan,

This tutorial is focused on react js bootstrap navbar example. It's a simple example of react js bootstrap navbar component example. This article goes in detailed on react bootstrap navbar not working. you will learn how to use bootstrap navbar in react.js. follow the below example for reactjs bootstrap navbar example.

Bootstrap is a wold best design framework right now. Currently bootstrap 4 and bootstrap 5 version is running. Bootstrap provides alerts, buttons, badge, card, modal, forms, collapse, navs, pagination etc.

In this post, i will show you step by step how to use bootstrap navbar component in reactjs app. we will create new react js project and install "react-bootstrap and bootstrap" npm packages for bootstrap, then we will use bootstrap navbar component with header link. so let's follow below command:

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app bootstrap-app
Step 2: Install React-Bootstrap

In this step, we will install bootstrap and react-bootstrap npm package for bootstrap design component. let's run below command:

npm install react-bootstrap bootstrap
Step 3: Import Bootstrap CSS File

In this step, we will import bootstrap css file in index.js file of react js app. so let's add it.

src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

reportWebVitals();
Step 4: Update App.js Component

Here, we will use bootstrap design class and button component for demo. so just update App.js file as the below:

src/App.js
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import NavDropdown from 'react-bootstrap/NavDropdown';
import Container from 'react-bootstrap/Container';

function App() {
  return (
    <div>
    <Navbar bg="light" expand="lg">
      <Container>
        <Navbar.Brand href="#home">React-Bootstrap</Navbar.Brand>
        <Navbar.Toggle aria-controls="basic-navbar-nav" />
        <Navbar.Collapse id="basic-navbar-nav">
          <Nav className="me-auto">
            <Nav.Link href="#home">Home</Nav.Link>
            <Nav.Link href="#link">Link</Nav.Link>
            <Nav.Link href="#link">Users</Nav.Link>
            <Nav.Link href="#link">Posts</Nav.Link>
            <NavDropdown title="Dropdown" id="basic-nav-dropdown">
              <NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
              <NavDropdown.Item href="#action/3.2">
                Another   
              </NavDropdown.Item>
              <NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
              <NavDropdown.Divider />
              <NavDropdown.Item href="#action/3.4">
                Separated link
              </NavDropdown.Item>
            </NavDropdown>
          </Nav>
        </Navbar.Collapse>
      </Container>
    </Navbar>

    <div className="container">
      <h1>React JS Bootstrap Navbar Component Example - Mywebtuts.com</h1> 

    </div>
    </div>
  );
}

export default App;
Step 5: Run React JS App

All the required steps have been done, now you have to type the given below command and hit enter to run the React app:

ng serve

Now, Go to your web browser, type the given URL and view the app output:

http://localhost:3000

In the last step run your project using bellow command.

Output

I hope it can help you...

#React JS