I am reading Bulma docs, took example to apply it on Codesandbox but the NavBar has a problem.
I imported Bulma as mentioned in docs, copied code, and I suppose Bulma is only css framework so no js to add.
The examples of Hero section that I am using can be found over here
The example provided with Hero head and Hero body and includes Nav bar is not working. The Navbar only as you see example here
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import "bulma/css/bulma.css";
function App() {
return (
<div className="App">
<section class="hero is-primary is-medium">
<div class="hero-head">
<nav class="navbar">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item">
<img
src="https://bulma.io/images/bulma-type-white.png"
alt="Logo"
/>
</a>
<span
class="navbar-burger burger"
data-target="navbarMenuHeroA"
>
<span />
<span />
<span />
</span>
</div>
<div id="navbarMenuHeroA" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item is-active">Home</a>
<a class="navbar-item">Examples</a>
<a class="navbar-item">Documentation</a>
<span class="navbar-item">
<a class="button is-primary is-inverted">
<span class="icon">
<i class="fab fa-github" />
</span>
<span>Download</span>
</a>
</span>
</div>
</div>
</div>
</nav>
</div>
<div class="hero-body">
<div class="container has-text-centered">
<h1 class="title">Title</h1>
<h2 class="subtitle">Subtitle</h2>
</div>
</div>
<div class="hero-foot">
<nav class="tabs">
<div class="container">
<ul>
<li class="is-active">
<a>Overview</a>
</li>
<li>
<a>Modifiers</a>
</li>
<li>
<a>Grid</a>
</li>
<li>
<a>Elements</a>
</li>
<li>
<a>Components</a>
</li>
<li>
<a>Layout</a>
</li>
</ul>
</div>
</nav>
</div>
</section>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Related
I have a code where this would essentially show links that you can press and would redirect you. I am have a problem where I am trying to click the link to "eco-news" and essentially open up a page with news articles in it. I have coded the news section, but I just dont know how to implement it.
Home > News > (directed to a new page where news would would populate)
import React from "react";
import './sidebar.css';
//import News from "../news section/News";
import { Link } from 'react-router-dom'
// Imported Images ==============>
import logo from '../../Assets/logo.png';
// Imported icons ===============>
import {IoMdSpeedometer} from 'react-icons/io';
import {TfiWorld} from 'react-icons/tfi';
import {BsQuestionCircle} from 'react-icons/bs'
// placeholder logo image
const Sidebar = () => {
return (
<div className="sideBar grid">
<div className="logoDiv flex">
<img src={logo} alt="World Space Logo" />
<h2>World Space.</h2>
</div>
<div className="menuDiv">
<h3 className="divTitle">
CONSUMPTION OVERVIEW
</h3>
<ul className="menuLists grid">
<li className="listItem">
<a href="/#" className="menuLink flex">
<IoMdSpeedometer className="icon" />
<span className="smallText">
Readout
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Driven Equivalent
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Efficiency Score
</span>
</a>
</li>
</ul>
</div>
{/* This is the tab for the Eco news, please update the necessary fonts and spacing */}
<div className="menuDiv">
<h3 className="divTitle">
NEWS
</h3>
<ul className="menuLists grid">
<li className="listItem">
{/* <a href=/News className="menuLink flex"> */}
<Link to ='\News' className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Eco-News
</span>
</Link>
{/* </a> */}
</li>
</ul>
</div>
<div className="settingsDiv">
<h3 className="divTitle">
SETTINGS
</h3>
<ul className="menuLists grid">
<li className="listItem">
<a href="/#" className="menuLink flex">
<IoMdSpeedometer className="icon" />
<span className="smallText">
Dashboard
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Consumption Overview
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Goals
</span>
</a>
</li>
<li className="listItem">
<a href="/#" className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Achievements
</span>
</a>
</li>
</ul>
</div>
<div className="sideBarCard">
<BsQuestionCircle className="icon" />
<div className="cardContent">
<h3>Help Center</h3>
{/*<p>Having trouble in World Space, please contact us.</p>
<button className="btn">Go to help center</button>*/}
</div>
</div>
</div>
);
}
export default Sidebar;
<div className="menuDiv">
<h3 className="divTitle">
NEWS
</h3>
<ul className="menuLists grid">
<li className="listItem">
{/* <a href=/News className="menuLink flex"> */}
<Link to ='\News' className="menuLink flex">
<TfiWorld className="icon" />
<span className="smallText">
Eco-News
</span>
</Link>
{/* </a> */}
</li>
</ul>
</div>
if you click the link it would lead to a broken page.
What it looks like so far
Ensure that you have followed the below steps as pre requisites
Create browser router
Add a route for your News component
Only then will your routing work
I'm having a hard time understanding how the routes and outlets work in react. My problem is this.
If I have a route that should load 3 parts.
-Top Menu
-Side Menu
-Center Content
But the center content is contained in the div thats wrapped by the "Side Menu" how do I wrap another element that will be changing inside of a previous component. My goal is to use the first 2 in all of the routes and based on the route the center content will change.
This is what it should look like
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
<div id="layoutSidenav_content"></div>
</div>
But for some reason all I can get is this
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
</div>
<div id="layoutSidenav_content"></div>
My react looks like this.
3 Components
Contains the top nav
contains the side nav
contains body elements that will change.
App()
<Route
path='/admin-dashboard'
element={
<>
<AdminNavigation />
<AdminNavigationLeft />
<AdminDashBoardHome />
</>
}
>
If I add <Outlet/> before the closing div in "layoutSideNav" component. nothing happens. If I remove the outlets from all components the app() looks the same. The top nav and side nave display correclty, but the center content is wonky.
I feel like routes is so much more abstract than I'm used to so maybe I'm just not thinking about it logically. Thank you so much for your help!
I tried using <Outlet/> to adjust how where the third component content displayed.
I've added my full code below for review.
const AdminNavigation = () =>{
const toggleSideMenu = event => {
// 👇️ toggle class on click
document.getElementsByTagName('body')[0].classList.toggle('sb-sidenav-toggled');
};
return (
<Fragment>
<nav className="sb-topnav navbar navbar-expand navbar-dark bg-dark">
<a className="navbar-brand ps-3" href="index.html">Woodmoore Improvement</a>
<button className="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" onClick={toggleSideMenu} id="sidebarToggle" href="#!"><i className="fas fa-bars"></i></button>
<form className="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
<div className="input-group">
<input className="form-control" type="text" placeholder="Search for..." aria-label="Search for..." aria-describedby="btnNavbarSearch" />
<button className="btn btn-primary" id="btnNavbarSearch" type="button"><i className="fas fa-search"></i></button>
</div>
</form>
<ul className="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i className="fas fa-user fa-fw"></i></a>
<ul className="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a className="dropdown-item" href="#!">Settings</a></li>
<li><hr className="dropdown-divider" /></li>
<li><a className="dropdown-item" href="#!">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</Fragment>
)
}
export default AdminNavigation;
const AdminDashBoardHome = () => {
return(
<Fragment>
<div id='layoutSidenav_content'>
<main>
<div className='container-fluid px-4'>
<h1 className='mt-4'>HOA Member Manager</h1>
<ol className='breadcrumb mb-4'>
<li className='breadcrumb-item active'>Member Map</li>
</ol>
<div className='row'>
<div className='col-lg-12'>
<div className='embed-responsive embed-responsive-16by9'>
<div id='map_canvas' className='embed-responsive-item pb-4' >
</div>
</div>
</div>
</div>
<div className='row'>
</div>
<div className='card mb-4'>
<div className='card-header'>
<i className='fas fa-table me-1'></i>
Member Lookup
</div>
<MemberDataList/>
</div>
</div>
</main>
<footer className='py-4 bg-light mt-auto'>
<div className='container-fluid px-4'>
<div className='d-flex align-items-center justify-content-between small'>
<div className='text-muted'>Copyright © Your Website 2022</div>
<div>
<a href='#'>Privacy Policy</a>
·
<a href='#'>Terms & Conditions</a>
</div>
</div>
</div>
</footer>
</div>
</Fragment>
)
}
export default AdminDashBoardHome;
const AdminNavigationLeft = () => {
document.body.classList.add('sb-nav-fixed');
return(
<Fragment>
<div id="layoutSidenav">
<Outlet/>
<div id="layoutSidenav_nav">
<nav className="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
<div className="sb-sidenav-menu">
<div className="nav">
<div className="sb-sidenav-menu-heading">Core</div>
<a className="nav-link" href="index.html">
<div className="sb-nav-link-icon"><i className="fas fa-tachometer-alt"></i></div>
Dashboard
</a>
<div className="sb-sidenav-menu-heading">Interface</div>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapseLayouts" aria-expanded="false" aria-controls="collapseLayouts">
<div className="sb-nav-link-icon"><i className="fas fa-columns"></i></div>
Layouts
<div className="sb-sidenav-collapse-arrow"><i className="fas fa-angle-down"></i></div>
</a>
<div className="collapse" id="collapseLayouts" aria-labelledby="headingOne" data-bs-parent="#sidenavAccordion">
<nav className="sb-sidenav-menu-nested nav">
<a className="nav-link" href="layout-static.html">Static Navigation</a>
<a className="nav-link" href="layout-sidenav-light.html">Light Sidenav</a>
</nav>
</div>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#collapsePages" aria-expanded="false" aria-controls="collapsePages">
<div className="sb-nav-link-icon"><i className="fas fa-book-open"></i></div>
Admin Management
<div className="sb-sidenav-collapse-arrow"><i className="fas fa-angle-down"></i></div>
</a>
<div className="collapse" id="collapsePages" aria-labelledby="headingTwo" data-bs-parent="#sidenavAccordion">
<nav className="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
Manage Users
</a>
<a className="nav-link collapsed" href="#" data-bs-toggle="collapse" data-bs-target="#pagesCollapseAuth" aria-expanded="false" aria-controls="pagesCollapseAuth">
Create New
</a>
</nav>
</div>
</div>
</div>
<div className="sb-sidenav-footer">
<div className="small">Logged in as:</div>
Start Bootstrap
</div>
</nav>
</div>
</div>
</Fragment>
)
}
export default AdminNavigationLeft;
If the following is what you intend to be rendered:
<div id="layoutSideNav">
<div id="layoutsidenav_nav"></div>
<div id="layoutSidenav_content"></div>
</div>
Then I suspect you want the routed content to be rendered in the layoutSidenav_content div. Something like the following:
<div id="layoutSideNav">
<div id="layoutsidenav_nav">
... navbar content ...
</div>
<div id="layoutSidenav_content">
... routed content ...
</div>
</div>
In other words, the above snippet describes a layout component, the routed content is the logical place for an Outlet component wrapping nested routes to output their element content into. The route may look like:
const AdminLayout = () => (
<>
<AdminNavigation />
<div id="layoutsidenav">
<div id="layoutSidenav_nav">
<AdminNavigationLeft />
</div>
<div id="layoutsidenav_content">
<Outlet />
</div>
</div>
</>
);
<Route
path='/admin-dashboard'
element={<AdminLayout />}
>
<Route index element={<AdminDashBoardHome />} />
... other admin routes
</Route>
const AdminNavigationLeft = () => {
useEffect(() => {
document.body.classList.add('sb-nav-fixed');
}, []);
return (
<nav className="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
<div className="sb-sidenav-menu">
...
</div>
</nav>
)
}
const AdminDashBoardHome = () => {
return (
<Fragment>
<main>
...
</main>
<footer className='py-4 bg-light mt-auto'>
...
</footer>
</Fragment>
)
}
I solved my own question.
You need to run the props through the component you're trying to display. The solution should be like this.
App()
<Route path='/admin-dashboard' element={<><AdminNavigation /><AdminNavigationLeft><AdminDashBoardHome/></AdminNavigationLeft></>}>
AdminDashLeft()
const AdminNavigationLeft = (props) => {
{props.children} // This is where the child component should display
}
I have taken advantage of the NavLink styling to add the active class to the current page menu item link. I am also using "exact in the Navs. However, I am unable to remove the active class from the Home page. Can anyone please take a look at my code and see if I am missing something? Thank you. The code is as follows:
app.js -
import React, { Component } from 'react';
import './App.css';
import { HashRouter as Router, Route } from 'react-router-dom';
import Inicio from './pages/Inicio';
import Gamification from './pages/Gamification';
import TotalMultimedia from './pages/TotalMultimedia';
import ELearning from './pages/ELearning';
import AbsoluteEngagement from './pages/AbsoluteEngagement';
import Nosotros from './pages/Nosotros';
import Contacto from './pages/Contacto';
class App extends Component {
render() {
return (
<Router basename="/">
<div>
<Route exact path='/' component={Inicio} />
<Route exact path='/Gamification' component={Gamification} />
<Route exact path='/TotalMultimedia' component={TotalMultimedia} />
<Route exact path='/ELearning' component={ELearning} />
<Route exact path='/AbsoluteEngagement' component=
{AbsoluteEngagement} />
<Route exact path='/Nosotros' component={Nosotros} />
<Route exact path='/Contacto' component={Contacto} />
</div>
</Router>
);
}
}
export default App;
Navbar.js -
import React, { Component } from 'react';
import './Navbar.css';
import { NavLink } from 'react-router-dom';
const isActivefunc = (match, location) => {
console.log(match, location)
return match
}
class Navbar extends Component {
render() {
return (
<div className="nav-wrapper">
<nav className="navbar nav-container pb-3 navbar-expand-md navbar-dark overlay">
<NavLink exact to="/"className="navbar-brand"></NavLink>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarsExampleDefault">
<ul className="navbar-nav ml-auto">
<li className="nav-item active">
<NavLink
isActive={isActivefunc}
exact activeClassName="active"
className="nav-link text-uppercase"
to="/">Inicio</NavLink>
</li>
<li className="nav-item dropdown">
<NavLink exact to="/Servicios" activeClassName="active" className="nav-link text-uppercase dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Servicios</NavLink>
<div className="dropdown-menu" aria-labelledby="dropdown01">
<NavLink exact to="/Gamification" activeClassName="main-nav-active-dropdown" className="dropdown-item text-uppercase font-weight-bold">Gamification Projects</NavLink>
<NavLink exact to="/TotalMultimedia" activeClassName="main-nav-active-dropdown" className="dropdown-item text-uppercase font-weight-bold">Total Multimedia</NavLink>
<NavLink exact to="/ELearning" activeClassName="main-nav-active-dropdown" className="dropdown-item text-uppercase font-weight-bold">Full E-Learning Platform</NavLink>
<NavLink exact to="/AbsoluteEngagement" activeClassName="main-nav-active-dropdown" className="dropdown-item text-uppercase font-weight-bold">Absolute Engagement Program</NavLink>
</div>
</li>
<li className="nav-item">
<NavLink exact to="/Nosotros" activeClassName="active" className="nav-link text-uppercase">Nosotros</NavLink>
</li>
<li className="nav-item">
<NavLink exact to="/Contacto" activeClassName="active" className="nav-link text-uppercase">Contacto</NavLink>
</li>
</ul>
</div>
</nav>
</div>
);
}
}
export default Navbar
Homepage -
import React, { Component } from 'react';
import './Inicio.css';
import { Link } from 'react-router-dom';
import Navbar from '../components/Navbar';
import Jumbotron1 from '../components/Jumbotron1';
import Footer from '../components/Footer';
class Inicio extends Component {
render() {
return (
<div>
<Navbar />
<Jumbotron1 />
<div className="content-container mt-3 mb-1 pt-5 pb-5">
<div className="content-img-1">
<div className="image-inner">
<div className="caption-background">
<div className="caption caption text-center pt-1 text-uppercase">1. Total Multimedia</div>
<div className="sub-caption text-center pb-1">
<h3>Realizamos sus tutoriales, videos, descargables y más, la mejor experiencia en capacitación</h3>
</div>
<div className="button-holder">
<Link to='/TotalMultimedia' className="btn btn-primary text-uppercase" role="button">Ver Detalles</Link>
</div>
</div>
</div>
</div>
</div>
<div className="content-container mb-2 pt-5 pb-5">
<div className="content-img-2">
<div className="image-inner">
<div className="caption-background">
<div className="caption caption text-center pt-1 text-uppercase">2. Gamification Projects</div>
<div className="sub-caption text-center pb-1">
<h3>Desarrollamos el potencial de cada persona con juegos, aplicaciones y más, las herramientas más innovadoras en capacitación</h3>
</div>
<div className="button-holder">
<Link to='/Gamification' className="btn btn-primary text-uppercase" role="button">Ver Detalles</Link>
</div>
</div>
</div>
</div>
</div>
<div className="content-container mb-2 pt-5 pb-5">
<div className="content-img-3">
<div className="image-inner">
<div className="caption-background">
<div className="caption caption text-center pt-1 text-uppercase">3. Full E-Learning Platform</div>
<div className="sub-caption text-center pb-1">
<h3>Creamos una plataforma para todos sus materiales de formación, totalmente interactivos y atractivos</h3>
</div>
<div className="button-holder">
<Link to='/ELearning' className="btn btn-primary text-uppercase" role="button">Ver Detalles</Link>
</div>
</div>
</div>
</div>
</div>
<div className="content-container mb-2 pt-5">
<div className="content-img-4">
<div className="image-inner">
<div className="caption-background">
<div className="caption caption text-center pt-1 text-uppercase">4. ABSOLUTE ENGAGEMENT PROGRAM</div>
<div className="sub-caption text-center pb-1">
<h3>El poder de todas nuestras soluciones en un solo programa incomparable</h3>
</div>
<div className="button-holder">
<Link to='/AbsoluteEngagement' className="btn btn-primary text-uppercase" role="button">Ver Detalles</Link>
</div>
</div>
</div>
</div>
</div>
<div className="content-container text-center mb-2 pt-5 pb-5">
<div className="row">
<div className="col-lg-3 col-md-6 spacing">
<Link to='/TotalMultimedia' className="blue-links">Multimedia</Link>
</div>
<div className="col-lg-3 col-md-6 spacing">
<Link to='/Gamification' className="blue-links">Gamification</Link>
</div>
<div className="col-lg-3 col-md-6 spacing">
<Link to='/ELearning' className="blue-links">Platform</Link>
</div>
<div className="col-lg-3 col-md-6 spacing">
<Link to='/AbsoluteEngagement' className="blue-links">Absolute Program</Link>
</div>
</div>
</div>
<div class="images-section pt-3 pb-3">
<div class="container pt-5 pb-5">
<div class="owl-carousel owl-theme">
<div class="item"><img class="grey" src="/assets/img/Renault-e1437433948637.jpg" alt="" /></div>
<div class="item"><img class="grey" src="/assets/img/hsbc.jpg" alt="" /></div>
<div class="item"><img class="grey" src="/assets/img/hiab.jpg" alt="" /></div>
<div class="item"><img class="grey" src="/assets/img/ge.jpg" alt="" /></div>
<div class="item"><img class="grey" src="/assets/img/holiday-inn.jpg" alt="" /></div>
<div class="item"><img class="grey" src="/assets/img/toyota.jpg" alt="" /></div>
</div>
</div>
</div>
<Footer />
</div>
);
}
}
export default Inicio
Demo site can be found at https://rrspark.com/lionsfieldcom
I found my problem. I simply forgot to remove the active class that shipped with the bootstrap example that I copied (dangers of cut and paste). The problem can be seen right after the nav-item class in the Navbar.js file.
I have been trying to port an html website to Gatsbyjs and React.
When building the header compartement I get an error "Adjacent JSX elements must be wrapped in an enclosing tag" error at the line with the .
I couldn't figure out the problem, and kindly ask for help.
The reason that I am building it with stateful component is that I will add some extra functionality to it later on.
This is my code:
import React, {Component} from 'react'
import { Link } from 'gatsby'
import { graphql } from 'gatsby'
import Img from 'gatsby-image'
import get from 'lodash/get'
import PropTypes from 'prop-types'
import Image from 'components/image'
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {
windowWidth: 1081,
mobileNavVisible: false
};
}
renderNavigation() {
<div className="site-logo retina pull-left"><Link to="/"><Img file="ChefsChoiceLogo300x300_DarkBG.png" width="120px" alt="Chef's Choice Logo" draggable="true"/></Link></div>
//Site Navigation-->
<nav className="navbar pull-right">
<div className="navbar-header">
<button type="button" data-toggle="collapse" data-target=".site-navigation" className="navbar-toggle"><span className="sr-only">Gezinti Bölmesini Aç/Kapa</span><span className="fa fa-bars"></span></button>
</div>
<ul className="site-navigation">
<li className="active"><Link to="/">Anasayfa</Link>
</li>
<li><Link to="menu" >Menü</Link>
</li>
<li><Link to="contact">İletişim</Link></li>
</ul>
</nav>
}
render() {
return(
<div className="menu-style-2 responsive sticky-menu">
<div className="site-wrapper">
<header className="site-header">
<div className="container">
<div className="row">
{this.renderNavigation()}
</div>
</div>
</header>
</div>
</div>
)
}
}
export default Header
I see two issues.
1) You need to do what it says and wrap your renderNavigation jsx with only one root element...
2) You need a return statement there as well...
renderNavigation() {
return (
<React.Fragment>
<div className="site-logo retina pull-left"><Link to="/"><Img file="ChefsChoiceLogo300x300_DarkBG.png" width="120px" alt="Chef's Choice Logo" draggable="true" /></Link></div>
//Site Navigation-->
<nav className="navbar pull-right">
<div className="navbar-header">
<button type="button" data-toggle="collapse" data-target=".site-navigation" className="navbar-toggle"><span className="sr-only">Gezinti Bölmesini Aç/Kapa</span><span className="fa fa-bars"></span></button>
</div>
<ul className="site-navigation">
<li className="active"><Link to="/">Anasayfa</Link>
</li>
<li><Link to="menu" >Menü</Link>
</li>
<li><Link to="contact">İletişim</Link></li>
</ul>
</nav>
<React.Fragment>
)}
First of all, renderNavigation() doesn't seem to return anything.
Second, you are returning (?) a div and a nav side by side. These need to be wrapped in a container. You can only return one element.
renderNavigation() {
return ( <-- add this
<div className="wrapper"> <-- add this
<div className="site-logo retina pull-left"><Link to="/"><Img file="ChefsChoiceLogo300x300_DarkBG.png" width="120px" alt="Chef's Choice Logo" draggable="true"/></Link></div>
//Site Navigation-->
<nav className="navbar pull-right">
<div className="navbar-header">
<button type="button" data-toggle="collapse" data-target=".site-navigation" className="navbar-toggle"><span className="sr-only">Gezinti Bölmesini Aç/Kapa</span><span className="fa fa-bars"></span></button>
</div>
<ul className="site-navigation">
<li className="active"><Link to="/">Anasayfa</Link>
</li>
<li><Link to="menu" >Menü</Link>
</li>
<li><Link to="contact">İletişim</Link></li>
</ul>
</nav>
</div> <-- add this
); <-- add this
}
In the renderNavigation wrap everything inside divs and return as you have it in the render function.
renderNavigation() {
return(
<div>
<div className="site-logo retina pull-left"><Link to="/"><Img file="ChefsChoiceLogo300x300_DarkBG.png" width="120px" alt="Chef's Choice Logo" draggable="true"/></Link></div>
//Site Navigation-->
<nav className="navbar pull-right">
<div className="navbar-header">
<button type="button" data-toggle="collapse" data-target=".site-navigation" className="navbar-toggle"><span className="sr-only">Gezinti Bölmesini Aç/Kapa</span><span className="fa fa-bars"></span></button>
</div>
<ul className="site-navigation">
<li className="active"><Link to="/">Anasayfa</Link>
</li>
<li><Link to="menu" >Menü</Link>
</li>
<li><Link to="contact">İletişim</Link></li>
</ul>
</nav>
</div>
)
}
I´m trying to build a Boostrap 4 NavBar that will use ReactJS <Link> component from react-router instead of the original <li> class.
Currently I´m having troubles building the component correctly, as at the end the ReactJS component has not the expected behaviour.
Let´s start from the original Boostrap 4 NavBar example:
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
This is being migrated to a ReactJS component as the following:
import React from 'react';
import Link from 'react-router-dom/Link';
function Menu() {
return (
<div>
<nav className="navbar navbar-toggleable-md navbar-light bg-faded">
<button className="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<a className="navbar-brand" href="#">Navbar</a>
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav mr-auto">
<span className="nav-item active">
<Link className="nav-link" to="/">Home <span className="sr-only">(current)</span></Link>
</span>
<span className="nav-item">
<Link className="nav-link" to="/counter">Counter</Link>
</span>
<span className="nav-item">
<Link className="nav-link disabled" to="/about">About</Link>
</span>
</ul>
<form className="form-inline my-2 my-lg-0">
<input className="form-control mr-sm-2" type="text" placeholder="Search" />
<button className="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</div>
);
}
export default Menu;
Altough it runs, many of the formatting is lost and some features like "nav-link disabled" are not working (you can click on About and it goes to the desired page).
I´m sure I´m doing the conversion wrong, so help is appreciated here to fix the component code so that to reflect correctly the original behaviour without React.
Maybe you got it resolved. Here's a working example with Bootstrap 4:
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Route, Switch, Link } from 'react-router-dom';
const AppPage = () => <h1>React Router 4 & Bootstrap 4</h1>
const HomePage = () => <h1>Welcome Home !</h1>
const AboutPage = () => <h1>About Us</h1>
const OneMorePage = () => <h1>One More Page !</h1>
const PrimaryLayout = () => (
<div>
<nav className="navbar navbar-expand-md navbar-dark bg-dark">
<Link className="navbar-brand" to="/">App</Link>
<button type="button" className="navbar-toggler" data-toggle="collapse" data-target="#navbarNav">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNav">
<ul className="navbar-nav mr-auto">
<li className="nav-item"><Link className="nav-link" to="/home">Home</Link></li>
<li className="nav-item"><Link className="nav-link" to="/about">About</Link></li>
<li className="nav-item"><Link className="nav-link" to="/one">More</Link></li>
</ul>
</div>
</nav>
<div className="container-fluid">
<Switch>
<Route path="/" exact component={AppPage} />
<Route path="/home" component={HomePage} />
<Route path="/about" component={AboutPage} />
<Route path="/one" component={OneMorePage} />
</Switch>
</div>
</div>
)
const App = () => (
<BrowserRouter>
<PrimaryLayout />
</BrowserRouter>
)
render(<App />, document.getElementById('root'))
For this particular use case, there's an easy solution.
Simply add this to your css:
.nav-link.disabled { pointer-events: none }.
That said, I'd strongly recommend to use a library of bootstrap-based react components on the long term. I personally like https://reactstrap.github.io/.
The problem is Bootstrap has a Javascript component as well which will not work in React as it clashes with React's Javascript. The CSS portion works which is what you are seeing.
You should use something like React-Bootstrap- https://react-bootstrap.github.io/. These are all the Bootstrap components written as React components so you can use them in the standard React manner by importing and using them in your JSX.