Bootstrap Navigation Bar doesn't work on live website - html

My navigation bar which I created using Bootstrap Offcanvas Example works perfectly fine in my local environment. But after uploading my build to a live website the navigation links lead to a 404 Error saying the page does not exist. However, my footer at the bottom is able to link and load pages properly.
Here is my Navbar:
import React from "react";
import logo from './logo_small.png';
import styled from 'styled-components';
import Button from 'react-bootstrap/Button';
import Container from 'react-bootstrap/Container';
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import NavDropdown from 'react-bootstrap/NavDropdown';
import Offcanvas from 'react-bootstrap/Offcanvas';
const Styles = styled.div`
.test{
color: black;
&:hover{
color: #30b849;
}
}
.button{
background-color: #30b849;
color: white;
padding: 5px 10px;
border: 1px solid #30b849;
transition: all 0.3s ease-out;
margin-right: 5%;
&:hover{
background: #000066;
color: white;
transition: all 0.3s ease-out;
}
}
.nav-item.dropdown:hover .dropdown-menu {
display: block;
}
.logo{
margin-left: 10%;
}
`;
function OffcanvasExample() {
return (
<Styles>
{['xl'].map((expand) => (
<Navbar key={expand} bg="white" expand={expand} className="navbar">
<Container fluid>
<Navbar.Brand href="/"><img className='logo' src={logo} alt="Depo App Logo"/></Navbar.Brand>
<Navbar.Toggle aria-controls={`offcanvasNavbar-expand-${expand}`} />
<Navbar.Offcanvas
id={`offcanvasNavbar-expand-${expand}`}
aria-labelledby={`offcanvasNavbarLabel-expand-${expand}`}
placement="end"
>
<Offcanvas.Header closeButton>
<Offcanvas.Title id={`offcanvasNavbarLabel-expand-${expand}`}>
<img src={logo} alt="Depo App Logo"/>
</Offcanvas.Title>
</Offcanvas.Header>
<Offcanvas.Body>
<Nav className="justify-content-lg-end flex-grow-1">
<Nav.Link href="/" className="ps-3 pe-5 fs-5">Home</Nav.Link>
<NavDropdown
href = "/"
className="ps-3 pe-5 fs-5"
title="App"
id={`offcanvasNavbarDropdown-expand-${expand}`}
renderMenuOnMount={true}
>
<NavDropdown.Item href="/our-app">Our App</NavDropdown.Item>
<NavDropdown.Item href="/lawyers">Lawyers</NavDropdown.Item>
<NavDropdown.Item href="/freelancers">Freelancers</NavDropdown.Item>
</NavDropdown>
<NavDropdown
className="ps-3 pe-5 fs-5"
title="Company"
id={`offcanvasNavbarDropdown-expand-${expand}`}
renderMenuOnMount={true}
>
<NavDropdown.Item href="/about-us">About Us</NavDropdown.Item>
<NavDropdown.Item href="/contact-us" >Contact Us</NavDropdown.Item>
<NavDropdown.Item href="/tech-support">Tech Support</NavDropdown.Item>
</NavDropdown>
</Nav>
<Nav.Link href="/sign-in" className="fs-5">Sign In</Nav.Link>
<Button href="/sign-up" className="button fs-5" >Sign Up</Button>
</Offcanvas.Body>
</Navbar.Offcanvas>
</Container>
</Navbar>
))}
</Styles>
);
}
export default OffcanvasExample;
Here is the app.js:
import {BrowserRouter as Router, Switch, Route} from "react-router-dom";
import Nav from './components/Nav';
import './App.css';
import Home from './components/pages/Home/Home'
import SignIn from './components/SignIn/Form'
import SignUp from './components/SignUp/Form'
import Lawyer from "./components/pages/Lawyers/Lawyers";
import Freelancer from "./components/pages/Freelancers/Freelancers";
import About_Us from "./components/pages/About_Us/About_Us";
import Our_App from "./components/pages/Our_App/Our_App";
import Contact_Us from "./components/pages/Contact_Us/Contact_Us";
import Tech_Support from "./components/pages/Tech_Support/Tech_Support";
import Terms_Of_Use from "./components/pages/Terms_Of_Use/Terms_Of_Use";
import Privacy_Policy from "./components/pages/Privacy_Policy/Privacy_Policy";
function App() {
return (
<>
<Router>
<Nav/>
<Switch>
<Route path = '/' exact component={Home}/>
<Route path = '/sign-up' component={SignUp}/>
<Route path = '/sign-in' component={SignIn}/>
<Route path = '/lawyers' component={Lawyer}/>
<Route path = '/freelancers' component={Freelancer}/>
<Route path = '/about-us' component={About_Us}/>
<Route path = '/our-app' component={Our_App}/>
<Route path = '/contact-us' component={Contact_Us}/>
<Route path = '/tech-support' component={Tech_Support}/>
<Route path = '/terms-of-use' component={Terms_Of_Use}/>
<Route path = '/privacy-policy' component={Privacy_Policy}/>
</Switch>
</Router>
</>
);
}
export default App;
Here is a link to the live website: https://thedepoapp.com/
Thanks for the help!

You are using the hrefs on a <NavDropdown.Item> you should be using hrefs only on <Nav.Link> components.
You can alter the dropdowns to these:
<NavDropdown.Item >
<Nav.Link href="/other-route">Other Route</Nav.Link>
</NavDropdown.Item>
See the docs for more details: https://react-bootstrap.github.io/components/navs/#using-dropdowns

Related

A class is repeated on other classes with react-spa-prerender

I use React SPA Prerender to optimize SEO, and i got this problem :
I have a class called HomeTitleContainer, specifically used for the Home.jsx file, which is the home page.
import { Container } from 'react-bootstrap';
import Link from '../immutable/nav/Link';
import './Home.css';
const Home = () => {
return (
<>
<Container className="HomeTitleContainer">
Ma Thématique
</Container>
<Container className="TableOfContentsLink">
<p><Link link={'/cours'} internalLink={true} >- Des cours de mathématiques sur de nombreux sujets</Link></p>
<p><Link link={'/bds-de-jpp'} internalLink={true} >- Des BDs de Jean-Petit</Link></p>
<p><Link link={'/jeux'} internalLink={true} >- Des petits jeux pour s'améliorer</Link></p>
</Container>
</>
);
}
export default Home;
Here is the corresponding css file, Home.css :
.HomeTitleContainer {
position: relative;
top: 30px;
/* background-color: var(--front-color); */
background-image: linear-gradient(to bottom right, var(--front-color), grey);
border-radius: 10px;
color: var(--links-color);
font-size: large;
padding: 30px;
width: calc(var(--window-width) * 3 / 4);
box-shadow: 20px 20px 5px 5px var(--navbar-color);
margin-bottom: 100px;
}
#media (min-width : 450px) {
.HomeTitleContainer {
width: calc(var(--window-width) * 1 / 2);
top: 50px;
}
}
This HomeTitleContainer class is not present anywhere else.
But when i generate some html files according to my .rsp.json file, this class is present in all other generated html files.
To illustrate it, an example with the courses page...
All the pages have a table of content, so I use this file, GenericTableOfContents.jsx :
import { Container, Row, Col } from 'react-bootstrap';
import Link from '../immutable/nav/Link';
const GenericTableOfContents = ( {items, prefix, title} ) => {
return (
<>
<p className="MainTitle">{title}</p>
<Row>
{
items.map(item => (
<Container key={item.id} className="TableOfContents">
<Col xs={12} md={12}>
<div key={item.id} className="TableOfContentsLink" >
<Link link={`/${prefix}/${item.relativePath}`} internalLink={true} >
<div>{item.title}</div>
</Link>
</div>
</Col>
</Container>
))
}
</Row>
</>
)
}
export default GenericTableOfContents;
You can see that the MainTitle and the TableOfContents classes should be one after the other.
But in cours.html, this sample is present :
<p class="MainTitle">Tous les cours</p>
<div class="HomeTitleContainer container">
<div class="TableOfContents container"> ...
Eventhough it shouldn't have to be there, a div with the HomeTitleContainer class has been added.
Here is the .rsp.json :
{
"port": 3000,
"buildDirectory": "./build",
"routes": [
"/",
"/cours",
"/bds-de-jpp",
"/jeux",
"/liens"
]
}
Here is the routes file (AppRoutes.jsx):
import { Route, Routes } from 'react-router-dom';
import Home from './components/home/Home';
import CoursesTableOfContents from './components/courses/CoursesTableOfContents';
import ChaptersTableOfContents from './components/courses/ChaptersTableOfContents';
import GenericChapter from './components/courses/GenericChapter';
import PdfTableOfContents from './components/pdf-viewer/PdfTableOfContents';
import PDFViewerPage from './components/pdf-viewer/PDFViewerPage';
import GamesTableOfContents from './components/games/GamesTableOfContents';
import Links from './components/links/Links';
import VCard from './components/contact/VCard';
import Error from './components/immutable/Error';
const AppRoutes = ( {courseItems, pdfItems, gameItems} ) => {
return <Routes>
{
process.env.NODE_ENV === 'development' ?
<Route exact path="/" element={<Home />} />
: <Route exact path="/" element={<Home />} />
}
<Route path="/cours" element={<CoursesTableOfContents courseItems={courseItems} />} />
{courseItems.map(courseItem => {
return <Route
key={courseItem.id}
path={`/cours/${courseItem.relativePath}`}
element={<ChaptersTableOfContents courseItem={courseItem} />} />
})}
{courseItems.map(courseItem => (
courseItem.chapters.map(chapter => {
return <Route
key={chapter.id}
path={`/cours/${courseItem.relativePath}/${chapter.relativePath}`}
element={<GenericChapter chapter={chapter} courseItem={courseItem} />} />
})
))}
<Route path="/bds-de-jpp" element={<PdfTableOfContents pdfItems={pdfItems} />} />
{pdfItems.map(pdfItem => (
<Route
key={pdfItem.id}
path={`/bds-de-jpp/${pdfItem.relativePath}`}
element={<PDFViewerPage pdfItem={pdfItem} />} />
))}
<Route path="/jeux" element={<GamesTableOfContents gameItems={gameItems} />} />
{gameItems.map(gameItem => (
<Route
key={gameItem.id}
path={`/jeux/${gameItem.relativePath}`}
element={gameItem.component} />
))}
<Route path="/liens" element={<Links />} />
<Route path="/contact" element={<VCard />} />
<Route path="*" element={<Error />} status={404} />
</Routes>
}
export default AppRoutes;
Added in App.js :
var courseItems = coursesResourceBuilder();
var pdfItems = pdfResourceBuilder();
var gameItems = gamesResourceBuilder();
<div className="App" >
<div className={`${theme} ${font} CopyBook`}>
<BrowserRouter>
<Header courseItems = {courseItems} pdfItems ={pdfItems} gameItems={gameItems} />
<Container className = {` RelativeContainer ${playMode ? "PlayMode" : ''} ${isLoading ? "Blur" : ''} `} >
<AppRoutes courseItems={courseItems} pdfItems={pdfItems} gameItems={gameItems} />
</Container>
<Footer />
</BrowserRouter>
</div>
</div>
And here is the url of the website :
https://ma-thematique.netlify.app
https://ma-thematique.netlify.app/cours
Can somebody can help me please ?
You can try to use Styled Components to avoid CSS from applying globally:
import styled from 'styled-components';
const HomeTitleContainer = styled.span`
position: relative;
top: 30px;
background-image: linear-gradient(to bottom right, var(--front-color), grey);
border-radius: 10px;
color: var(--links-color);
font-size: large;
padding: 30px;
width: calc(var(--window-width) * 3 / 4);
box-shadow: 20px 20px 5px 5px var(--navbar-color);
margin-bottom: 100px;
#media (min-width: 450px) {
width: calc(var(--window-width) * 1 / 2);
top: 50px;
}
`;
export default HomeTitleContainer;
Then inside of your Home component:
import { Container } from 'react-bootstrap';
import Link from '../immutable/nav/Link';
import './Home.css';
import HomeTitleContainer from "./HomeTitleContainer";
import React, {Fragment} from "react";
const Home = () => (
<Fragment>
<Container>
<HomeTitleContainer>
Ma Thématique
</HomeTitleContainer>
</Container>
<Container className="TableOfContentsLink">
<p><Link link={'/cours'} internalLink={true} >- Des cours de mathématiques sur de nombreux sujets</Link></p>
<p><Link link={'/bds-de-jpp'} internalLink={true} >- Des BDs de Jean-Petit</Link></p>
<p><Link link={'/jeux'} internalLink={true} >- Des petits jeux pour s'améliorer</Link></p>
</Container>
</Fragment>
)
export default Home
Can you try this and let us know what the result is?
There are two things which attempt to solve the problem here:
Using empty tag instead of a Fragment - A Fragment allow you to group children without adding extra nodes to the DOM and make your component structure and rendering logic more clear and concise. Empty tags, on the other hand, do not provide these benefits and can lead to additional, unnecessary DOM nodes. This can cause some unusual behavior, especially in older versions of react.
Using a CSS file instead of styled-components. If you use a CSS file, the CSS will apply globally and if you are not careful enough, you can easily render a div with a class name that has defined properties in one of your CSS files.

How to style an a element that redirects to react component?

App.js:
import './App.css';
import logo from './images/logo.png';
import Home from './components/Home';
import About from './components/About';
import Calculators from './components/Calculators';
import Classes from './components/Classes';
import Riddles from './components/Riddles';
import { useRoutes, BrowserRouter as Router } from 'react-router-dom';
const MenuBar = () => {
return (
<header className='App-header'>
<div className="container">
<a id="home" className="content-tab" href="/"> Home</a>
<a id="about" className="content-tab" href="/about"> About</a>
<a id="calcs" className="content-tab" href="/calculators"> Calculators</a>
<a id="riddles" className="content-tab" href="/riddles">Riddles</a>
<a id="classes" className="content-tab" href="/classes">Classes</a>
</div>
</header>
)
}
const App = () => {
let routes = useRoutes([
{ path: "/", element: <Home /> },
{ path: "about", element: <About /> },
{ path: "classes", element: <Classes />},
{ path: "calculators", element: <Calculators />},
{ path: "riddles", element: <Riddles /> },
// ...
]);
return routes;
};
function AppWrapper() {
return (
<div className="App">
<MenuBar />
<Router>
<App />
</Router>
</div>
);
}
export default AppWrapper;
Now, I want to make that whenever you select a page, like home, about, calculators, etc; it marks the link using border-bottom: 1px solid white;, but when using
.container a.active {
border-bottom: 1px solid white;
}
It just doesn't work.
Any ideas why?
Can it be because it's redirecting to a different url?
If so, then should I also import app.css into my Home, About, etc components?
You should be using Link, or NavLink if you want to apply active styling, instead of the raw anchor <a /> tag. Use the function callback for the className prop which is passed an isActive prop.
NavLink
import { NavLink } from 'react-router-dom';
const MenuBar = () => {
const getLinkClassNames = ({ isActive }) => [
"content-tab",
isActive ? "active-tab" : null,
]
.filter(Boolean)
.join(" ");
return (
<header className='App-header'>
<div className="container">
<NavLink
id="home"
className={getLinkClassNames}
to="/"
>
Home
</NavLink>
<NavLink
id="about"
className={getLinkClassNames}
to="/about"
>
About
</NavLink>
<NavLink
id="calcs"
className={getLinkClassNames}
to="/calculators"
>
Calculators
</NavLink>
<NavLink
id="riddles"
className={getLinkClassNames}
to="/riddles"
>
Riddles
</NavLink>
<NavLink
id="classes"
className={getLinkClassNames}
to="/classes"
>
Classes
</NavLink>
</div>
</header>
);
}
CSS
.active-tab {
border-bottom: 1px solid white;
}
If you prefer the v5 syntax then create a custom NavLink component.
import { NavLink as BaseNavLink } from "react-router-dom";
const NavLink = React.forwardRef(
({ activeClassName, activeStyle, ...props }, ref) => {
return (
<BaseNavLink
ref={ref}
{...props}
className={({ isActive }) =>
[
props.className,
isActive ? activeClassName : null
]
.filter(Boolean)
.join(" ")
}
style={({ isActive }) => ({
...props.style,
...(isActive ? activeStyle : null)
})}
/>
);
}
);
Usage:
<NavLink
id="home"
className="content-tab"
activeClassName="active-tab"
to="/"
>
Home
</NavLink>

How to move/animate text values in navbar when I toggle the sidebar

How do I flex the contents of my navbar when I toggle the sidebar on/off in ReactJS? In my current website my sidebar overlaps the navbar so when I toggle it on, more than half of the title gets covered (sample1, sample2)
This is my Navbar.js
import React, { useState } from 'react'
import {Navbar, Container} from 'react-bootstrap'
import { Link } from 'react-router-dom';
import { useAuth } from "../contexts/AuthContext"
import './styles/styles.css';
import * as FaIcons from 'react-icons/fa';
import * as AiIcons from 'react-icons/ai';
import { IconContext } from 'react-icons';
import { SidebarItem } from './SidebarItem';
export default function Navubaru({component: Component, ...rest}) {
const { currentUser } = useAuth()
const [sidebar, setSidebar] = useState(false);
const showSidebar = () => setSidebar(!sidebar);
return (
<div>
<Navbar bg="myColor" variant="dark">
<IconContext.Provider value={{ color: '#fff' }}>
<Link to='#' className='menu-bars'>
<FaIcons.FaBars onClick={showSidebar} />
</Link>
<nav className={sidebar ? 'nav-menu active' : 'nav-menu'}>
<ul className='nav-menu-items' onClick={showSidebar}>
<li className='navbar-toggle'>
<Link to='#' className='menu-bars'>
<AiIcons.AiOutlineClose />
</Link>
</li>
{SidebarItem.map((item, index) => {
return (
<li key={index} className={item.cName}>
<Link to={item.path}>
{item.icon}
<span>{item.title}</span>
</Link>
</li>
);
})}
</ul>
</nav>
</IconContext.Provider>
<Container>
<Navbar.Brand href="/">Welcome to my Website</Navbar.Brand>
<Navbar.Toggle />
<Navbar.Collapse className="justify-content-end">
<Navbar.Text>
Signed in as: {currentUser && currentUser.email}
</Navbar.Text>
</Navbar.Collapse>
</Container>
</Navbar>
</div>
)
}
I'd also like to flex/minimize the size of the main page when I toggle the sidebar if there's not much difference in the methods of doing it. I'd appreciate any help and thoughts given. Thank you
You can set padding-left to the navbar's wrapper when sidebar is open and remove it when the sidebar close.
Here is an example navbar.

Make a sidebar from react-bootstrap

I am trying to create a Bootstrap sidebar like this picture here.
I have looked at all the code on react-bootstrap and Twitter Bootstrap and I am yet to find a how-to code this. Basically, if they are viewing on a desktop, I want the sidebar to be visible, otherwise hidden.
The sidebar should stay still while the content on the page scrolls up and down.
Ok so for people who want to make a sidebar sadly the news is you gotta make it all yourself.
What I have done is the following.
See the example at https://github.com/StartBootstrap/startbootstrap-simple-sidebar
Create sidebar.js somewhere in your app.
import React from "react";
import {Nav} from "react-bootstrap";
import { withRouter } from "react-router";
import '../pages/style/Dashboard.css'
const Side = props => {
return (
<>
<Nav className="col-md-12 d-none d-md-block bg-light sidebar"
activeKey="/home"
onSelect={selectedKey => alert(`selected ${selectedKey}`)}
>
<div className="sidebar-sticky"></div>
<Nav.Item>
<Nav.Link href="/home">Active</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="link-1">Link</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="link-2">Link</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="disabled" disabled>
Disabled
</Nav.Link>
</Nav.Item>
</Nav>
</>
);
};
const Sidebar = withRouter(Side);
export default Sidebar
My Dashboard.css has the following in it.
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
min-height: 100vh !important;
z-index: 100;
padding: 48px 0 0;
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
#sidebar-wrapper{
min-height: 100vh !important;
width: 100vw;
margin-left: -1rem;
-webkit-transition: margin .25s ease-out;
-moz-transition: margin .25s ease-out;
-o-transition: margin .25s ease-out;
transition: margin .25s ease-out;
}
#sidebar-wrapper .sidebar-heading {
padding: 0.875rem 1.25rem;
font-size: 1.2rem;
}
#page-content-wrapper {
min-width: 0;
width: 100%;
}
Then final step
In the file you want it to be show in do the following
import React from "react";
import {Container, Row, Col, Card, Form, Button } from "react-bootstrap";
import { withRouter } from "react-router";
import Sidebar from "../moduls/sidebar.js";
import './style/Dashboard.css'
const Dash = props => {
return (
<>
<Container fluid>
<Row>
<Col xs={2} id="sidebar-wrapper">
<Sidebar />
</Col>
<Col xs={10} id="page-content-wrapper">
this is a test
</Col>
</Row>
</Container>
</>
);
};
const Dashboard = withRouter(Dash);
export default Dashboard
As of 2022 there is pure react-boostrap based component called react-boostrap-sidebar-menu . It is the cleanest solution so far and quite customizable.
https://www.npmjs.com/package/react-bootstrap-sidebar-menu
https://github.com/ivp-dev/react-bootstrap-sidebar-menu
import SidebarMenu from 'react-bootstrap-sidebar-menu';
<SidebarMenu>
<SidebarMenu.Header>
<SidebarMenu.Brand>
{/* Your brand icon */}
</SidebarMenu.Brand>
<SidebarMenu.Toggle />
</SidebarMenu.Header>
<SidebarMenu.Body>
<SidebarMenu.Nav>
<SidebarMenu.Nav.Link>
<SidebarMenu.Nav.Icon>
{/* Menu item icon */}
</SidebarMenu.Nav.Icon>
<SidebarMenu.Nav.Title>
{/* Menu item title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Nav.Link>
<SidebarMenu.Nav/>
<SidebarMenu.Sub>
<SidebarMenu.Sub.Toggle>
<SidebarMenu.Nav.Icon />
<SidebarMenu.Nav.Title>
{/* Submenu title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Sub.Toggle>
<SidebarMenu.Sub.Collapse>
<SidebarMenu.Nav>
<SidebarMenu.Nav.Link>
<SidebarMenu.Nav.Icon>
{/* Submenu item icon */}
</SidebarMenu.Nav.Icon>
<SidebarMenu.Nav.Title>
{/* Submenu item title */}
</SidebarMenu.Nav.Title>
</SidebarMenu.Nav.Link>
</SidebarMenu.Nav>
</SidebarMenu.Sub.Collapse>
</SidebarMenu.Sub>
<SidebarMenu.Body/>
</SidebarMenu>
One can now use a library, react-bootstrap-drawer, which provides a sidenav / drawer which was taken directly from the react-bootstrap documentation. Oddly, this is not a component provided by the library itself so one must use a third-party library:
import 'react-bootstrap-drawer/lib/style.css';
import React, { useState } from 'react';
import {
Col,
Collapse,
Container,
Row,
} from 'react-bootstrap';
import { Drawer, } from 'react-bootstrap-drawer';
const ApplicationDrawer = (props) => {
const [open, setOpen] = useState(false);
const handleToggle = () => setOpen(!open);
return (
<Drawer { ...props }>
<Drawer.Toggle onClick={ handleToggle } />
<Collapse in={ open }>
<Drawer.Overflow>
<Drawer.ToC>
<Drawer.Header href="/">Application</Drawer.Header>
<Drawer.Nav>
<Drawer.Item href="/settings">Settings</Drawer.Item>
</Drawer.Nav>
</Drawer.ToC>
</Drawer.Overflow>
</Collapse>
</Drawer>
);
};
const Application = (props) => {
return (
<Container fluid>
<Row className="flex-xl-nowrap">
<Col as={ ApplicationDrawer } xs={ 12 } md={ 3 } lg={ 2 } />
<Col xs={ 12 } md={ 9 } lg={ 10 }>{ props.children }</Col>
</Row>
</Container>
);
};
See: https://github.com/SimpleSigner/react-bootstrap-drawer
of course, you have to make the navbar yourself and the examples above are very valid, but cdbreact speeds up the process a lot faster. just add cdbreact using
npm I cdbreact
or
yarn add cdbreact
and then import CDBSidebar, CDBSidebarContent, CDBSidebarHeader, etc. with cdbreact, you don't need to bother about installing bootsrap in your react app.
cdbreact also comes with icons, and a lot more.
import React from 'react'
import {CDBSidebar,
CDBSidebarContent,
CDBSidebarHeader,
CDBSidebarFooter, CDBSidebarMenu,
CDBSidebarMenuItem} from 'cdbreact';
import {NavLink, Link} from 'react-router-dom';
import {} from 'react-router-dom';
const Sidebar=()=>{
return (
<div style={{display:'flex', height:'100%', overflow:'scroll initial'}}>
<CDBSidebar textColer="#fff" backgroundColor="rgb(37, 90, 122)">
<CDBSidebarHeader prefix={<i className="fa fa-bars fa-large"></i>}>
<Link to="/dashboard">Dashboard</Link>
</CDBSidebarHeader>
<CDBSidebarContent className="sidebar-content">
<CDBSidebarMenu>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
<NavLink exact to="/dashboard" activeClassName="activeClicked">
<CDBSidebarMenuItem icon="columns">
Transfer
</CDBSidebarMenuItem>
</NavLink>
</CDBSidebarMenu>
</CDBSidebarContent>
<CDBSidebarFooter style={{textAlign:'center'}}>
<div className="sidebar-btn-wrapper" style={{ padding :'20px 5px' }}>
sidebar footer
</div>
</CDBSidebarFooter>
</CDBSidebar>
</div>
)
}
export default Sidebar;
you can also follow the guide here https://dev.to/devwares/how-to-create-a-responsive-sidebar-in-react-using-bootstrap-and-contrast-5gi2 follow this link to see

Added Bootstrap header and now the component is duplicating

I have added a Navbar from Bootstrap to a React App and for some reason, it is duplicating when I render the app. Not sure what is happening. Here is the code from below is my headercomponent.
import React, { Component } from 'react';
import Navbar from './Navbar.jsx';
class HeaderName extends Component {
render() {
return (
<div>
<div>
<Navbar />
</div>
<h1>The AquaStars New Website.</h1>
<img src="../public/images/picture_swimmers.png" />
</div>
)
}
}
export default HeaderName;
Below is the Navbar.jsx component.
import React,{ Component } from 'react';
import { Link } from 'react-router-dom';
import './Navbar.css';
class Navbar extends Component {
render() {
return (
<nav className="navbar navbar-expand-md navbar-dark bg-dark mb-4">
<a className="navbar-brand" href="#">Top navbar</a>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarCollapse">
<ul className="navbar-nav mr-auto">
<li className="nav-item active">
<a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Link</a>
</li>
<li className="nav-item">
<a className="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
);
}
}
export default Navbar;
Below is the index.js. This is where I think the problem is.
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route } from 'react-router-dom'
import HeaderName from './components/header';
import FooterName from './components/footer';
import DescripTitle from './components/descrip';
import DescripName from './components/intro';
//create a new componet. Produce some HTML.
// const App = function() {
// return <div>Welcome to Aquastars Website</div>;
// }
const App = () => {
return (
<div>
<Router>
<div>
<Route exact path="/" component={HeaderName}/>
</div>
</Router>
<HeaderName />
<DescripName />
<DescripTitle />
<FooterName />
</div>
);
}
//Take this component's generated HTML and put it
// on the page(in the DOM).
ReactDOM.render(<App />, document.querySelector('.container'));
Any help would be appreciated.
Make sure you are not rendering the Navbar component in your app.js/index.js or wherever the headerName component is being imported. Can you post these files as well? What is inside the Navbar component. More information is needed.
-EDIT-
You can make a new Component that brings In any page contents into a "page component" then in your render:
<HeaderName/>
<Router exact path="/somedirectory" component{yourPageComponent}/>
<FooterName/>
This will make sure that header and footer are rendered on every page but only certain content is rendered on route changes. Cheers.