Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to render a component only on the start page in React?

I want the "Home" component to only show on the start page. Now it’s visible on every page. What should I do? I have tried some options but there is still something I’m missing.

This is my Index.js:

import "./index.css";
import News from "./news";
import Nav from "./nav";
import Home from "./home";
import {BrowserRouter,Route} from "react-router-dom"

ReactDOM.render(
  <BrowserRouter>
  <Nav />
  <Route path="/" component={Home}></Route>
    <Route path="/Nintendo"><News newsName="nintendo+games" /></Route>
    <Route path="/Playstation"><News newsName="playstation+games"/></Route>
    <Route path="/Xbox"><News newsName="xbox+games" /></Route>
    <Route path="/PC"><News newsName="pc+games" /></Route>
    <Route path="/Retro"><News newsName="retro+games" /></Route>
    <Route path="/Indie"><News newsName="indie+games" /></Route>
  </BrowserRouter>,
  document.getElementById("root")
);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In this case I believe you can add the exact prop to the route:

<Route path="/" exact component={Home}></Route>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading