1
votes

I am newbie to react i basically have two questions. I am embedding a template into ReactJs.

  1. I am having problem with slider. My slider's text is showing on navigation bar and slider is also not working. It has inline styling.
  2. I have five components in my project. I would like to apply routing on one of them.

Original Slider

enter image description here

My Slider

enter image description here

Here are my code files

  1. index.html file

<!-- Document Wrapper
============================================= -->
<div id="wrapper" class="clearfix">
</div><!-- #wrapper end -->



    <!-- Go To Top
============================================= -->
<!-- <div id="gotoTop" class="icon-angle-up"></div> -->

<script src="/scripts/app.js"></script>

<!-- External JavaScripts
============================================= -->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/plugins.js"></script>

<!-- Footer Scripts
============================================= -->
<script type="text/javascript" src="js/functions.js"></script>

  1. Header.js

    import React from 'react'; import logo from './images/chatfit_logo.png' class Header extends React.Component { render() {

        return (
    
        <header id="header" className="transparent-header full-header" data-sticky-class="not-dark">
    
    <div id="header-wrap">
    
    <div className="container clearfix">
    
        <div id="primary-menu-trigger"><i className="icon-reorder"></i></div>
    
        <div id="logo">
            <a href="index.html" className="standard-logo" data-dark-logo="images/logo-dark.png"><img src={logo} alt="Chatfit logo" /></a>
            <a href="index.html" className="retina-logo" data-dark-logo="images/[email protected]"><img src="images/[email protected]" alt="Canvas Logo" /></a>
        </div>
    
        <nav id="primary-menu" className="dark">
    
            <ul>
                <li className="current"><a href="index.html"><div>Home</div></a>
                </li>
                <li><a href="#"><div>Our Mission</div></a>
                </li>
                <li className="mega-menu"><a href="#"><div>Services</div></a>
                </li>
                <li className="mega-menu"><a href="#"><div>App Overview</div></a>
                </li>
                <li className="mega-menu"><a href="#"><div>Team</div></a>
                </li>
                <li><a href="shop.html"><div>Contact Us</div></a>
                </li>
            </ul>
    
            <div id="top-cart">
                <a href="#" id="top-cart-trigger"><i className="icon-shopping-cart"></i><span>5</span></a>
                <div className="top-cart-content">
                    <div className="top-cart-title">
                        <h4>Shopping Cart</h4>
                    </div>
                    <div className="top-cart-items">
                        <div className="top-cart-item clearfix">
                            <div className="top-cart-item-image">
                                <a href="#"><img src="images/shop/small/1.jpg" alt="Blue Round-Neck Tshirt" /></a>
                            </div>
                            <div className="top-cart-item-desc">
                                <a href="#">Blue Round-Neck Tshirt</a>
                                <span className="top-cart-item-price">$19.99</span>
                                <span className="top-cart-item-quantity">x 2</span>
                            </div>
                        </div>
                        <div className="top-cart-item clearfix">
                            <div className="top-cart-item-image">
                                <a href="#"><img src="images/shop/small/6.jpg" alt="Light Blue Denim Dress" /></a>
                            </div>
                            <div className="top-cart-item-desc">
                                <a href="#">Light Blue Denim Dress</a>
                                <span className="top-cart-item-price">$24.99</span>
                                <span className="top-cart-item-quantity">x 3</span>
                            </div>
                        </div>
                    </div>
                    <div className="top-cart-action clearfix">
                        <span className="fleft top-checkout-price">$114.95</span>
                        <button className="button button-3d button-small nomargin fright">View Cart</button>
                    </div>
                </div>
            </div>
    
    
            <div id="top-search">
                <a href="#" id="top-search-trigger"><i className="icon-search3"></i><i className="icon-line-cross"></i></a>
                <form action="search.html" method="get">
                    <input type="text" name="q" className="form-control" value="" placeholder="Type &amp; Hit Enter.." readOnly/>
                </form>
            </div>
    
        </nav>
    
    </div>
    
    </div>
    </header>
    
        );
    }
    

    } export default Header;

  2. Slider.js

    import React from 'react'

    class Slider extends React.Component { render() { return(

                <div className="swiper-container swiper-parent">
                    <div className="swiper-wrapper">
                        <div className="swiper-slide dark" style={{backgroundImage: "url(images/slider/swiper/1.jpg)"}}>
                            <div className="container clearfix">
                                <div className="slider-caption slider-caption-center">
                                    <h2 data-caption-animate="fadeInUp">Welcome to Canvas</h2>
                                    <p data-caption-animate="fadeInUp" data-caption-delay="200">Create just what you need for your Perfect Website. Choose from a wide range of Elements &amp; simply put them on your own Canvas.</p>
                                </div>
                            </div>
                        </div>
                        <div className="swiper-slide dark">
                            <div className="container clearfix">
                                <div className="slider-caption slider-caption-center">
                                    <h2 data-caption-animate="fadeInUp">Beautifully Flexible</h2>
                                    <p data-caption-animate="fadeInUp" data-caption-delay="200">Looks beautiful &amp; ultra-sharp on Retina Screen Displays. Powerful Layout with Responsive functionality that can be adapted to any screen size.</p>
                                </div>
                            </div>
                            <div className="video-wrap">
                                <video id="slide-video" poster="images/videos/explore.jpg" preload="auto" loop autoPlay muted>
                                    <source src='images/videos/explore.webm' type='video/webm' />
                                    <source src='images/videos/explore.mp4' type='video/mp4' />
                                </video>
                                <div className="video-overlay" style={{backgroundColor: 'rgba(0,0,0,0.55)'}}></div>
                            </div>
                        </div>
                        <div className="swiper-slide" style={{backgroundImage: 'url(images/slider/swiper/3.jpg)' , backgroundPosition: 'center top'}}>
                            <div className="container clearfix">
                                <div className="slider-caption">
                                    <h2 data-caption-animate="fadeInUp">Great Performance</h2>
                                    <p data-caption-animate="fadeInUp" data-caption-delay="200">You'll be surprised to see the Final Results of your Creation &amp; would crave for more.</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="slider-arrow-left"><i className="icon-angle-left"></i></div>
                    <div id="slider-arrow-right"><i className="icon-angle-right"></i></div>
                </div>
    
                <a href="#" data-scrollto="#content" data-offset="100" className="dark one-page-arrow"><i className="icon-angle-down infinite animated fadeInDown"></i></a>
    
            </div>
        </section>
    
        );
    }
    

    }

    export default Slider;

  3. App.js

    import React from 'react'; import {BrowserRouter} from 'react-router-dom'; import Header from './Header' import Slider from './Slider'; import Section from './Section'; import Footer from './Footer' class IndecisionApp extends React.Component { render() {

        return (
            <BrowserRouter>
                <div className="wrapper"> 
                    <Header/>
                    <Slider />
                    <Section />
                    <Footer /> <!-- Register.js goes here but should show in another page
                </div>
            </BrowserRouter>
        );
    }
    

    }

    export default IndecisionApp;

Navigationbar and footer are same for Register.js. I want, when I click on Register link. It should redirect to Register.js also displaying header and footer What should I do.

Edit

Now in my App.js I have something like this

<BrowserRouter>
    <div className="wrapper"> 
        <Header/>
        <Route path="/register" component={Register}></Route>
        <Slider />
        <Section /> 
        <Footer />
     </div>
</BrowserRouter>

When i click on the link I want to hide Slider and Section

Thanks

2
DO you have any error in console ?Akhtar Munir
yes i have some warning in consoleQasim Ali
Check those warnings if for the libraries then correct your libraries for the slider etc... and for routing let me give you a simple code, it may help you.Akhtar Munir
my friend has embedded same template with almost same code as mine for him the slider is working fineQasim Ali
It can also be the problem if your libraries order is different. Kindly confirm that first.Akhtar Munir

2 Answers

0
votes

In here you can import the Link as you know.

    <ul>
        <li className="current"><Link to="/register"><div>Register</div></Link>
        </li>
        </li>
    </ul>

Here import the Route as you know

  For Example

 <BrowserRouter>
        <div className="wrapper"> 
            <Header/>
            <Slider />
            <Section />
            <Route path="/register" component="Your_register_component"></Route>
            <Footer /> <!-- Register.js goes here but should show in another page
        </div>
    </BrowserRouter>
0
votes

Try this @QasimAli

<BrowserRouter>
  <div className="wrapper"> 
      <Header/>
      <Route  exact path="/register" component={Register}></Route>
      <Slider />
      <Section /> 
      <Footer />
   </div>
</BrowserRouter>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>