Search code examples
reactjsbootstrap-4react-bootstrap

Why is my React App showing bootstrap navbar vertically?


I'm trying to write a react app with authentication. So some of the fields on the navbar would be showed only to authenticated users. For this purpose I have a Navbar.jsx file and a SignedInLinks.jsx file.

My NavBar.jsx:

import React from "react";
import { Link } from "react-router-dom";
import Signedinlinks from "./SignedInLinks";

const Navbar = () => {
  return (
    <nav className="navbar navbar-default navbar-dark bg-dark">
      <div className="container">
        <Link to="/" className="navbar-brand">
          RS
        </Link>
        <Signedinlinks />
      </div>
    </nav>
  );
};

export default Navbar;

My SignedInLinks.jsx:

import React from "react";

import { NavLink } from "react-router-dom";

const Signedinlinks = () => {
  return (
    <ul className="navbar-nav">
      <li className="nav-item">
        <NavLink to="/">Edit Blogs</NavLink>
      </li>
      <li className="nav-item">
        <NavLink to="/">Edit Photographs</NavLink>
      </li>
      <li className="nav-item">
        <NavLink to="/" className="btn btn-primary">
          RS
        </NavLink>
      </li>
    </ul>
  );
};

export default Signedinlinks;

I'm using the following for css in index.html:

<link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
      integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
      crossorigin="anonymous"
 />

And the index.css has :

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
    monospace;
}

Any idea why my navbar items are showing in a Vertical list? enter image description here


Solution

  • Because the Navbar doesn't contain one of the navbar-expand* classes. Read the docs...

    "Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl} for responsive collapsing and color scheme classes."

    Also, there is no navbar-default in Bootstrap 4.