0

Unable to see the header text returned in my Home and Tutorials page in my react hooks site. Below is my App.js, Navigation.js and Home.js. Could someone please advise about the problem here.

App.js

import React from 'react';
import { BrowserRouter, Route, Switch } from "react-router-dom";
import './App.css';
import Home from "./components/Home";
import Tutorials from "./components/Tutorials";
import Navigation from './components/Navigation';

function App() {
  return (
    <BrowserRouter>
        <Navigation>
          <Switch>
                <Route exact path="/" component={Home} />
                <Route path="/tutorials" component={Tutorials} />
          </Switch>
        </Navigation>
    </BrowserRouter>
  );
};

export default App;

Navigation.js

import React from 'react';
import { NavLink} from 'react-router-dom';

const Navigation = () => {

    return (
        <div className="App">
            <div className="wrapper">
                <div id="wrap">
                    <nav className="siteNavigation_nav_links">
                        <div className="row" ></div>
                        <div className="main_links_nav">
                            <NavLink className="mob_link" to="/">Home</NavLink>
                            <NavLink className="mob_link" to="/tutorials">Tutorials</NavLink>
                        </div>
                    </nav>
                </div>
            </div>
        </div>

    )

}

export default Navigation;

Home.js

import React from 'react';

const Home = () =>{

    return (
        <div className="App">
            <h1>This is Home Page !</h1>
        </div>
    )
}
export default Home;

Tutorials.js

import React from 'react';

const Tutorials = () =>{

    return (
        <div><h1>This is Tutorials Page !</h1></div>
    )
};
export default Tutorials;
soccerway
  • 10,371
  • 19
  • 67
  • 132

1 Answers1

1

Navigation is a Navbar component. And you want it everywhere on the site.

So, you can easily do it by using it outside the scope of the Switch component. In doing so, it will render all over your screens.

  <BrowserRouter>
        <Navigation />
          <Switch>
                <Route exact path="/" component={Home} />
                <Route path="/tutorials" component={Tutorials} />
          </Switch>
    </BrowserRouter>
Prateek Thapa
  • 4,829
  • 1
  • 9
  • 23