Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
components in index file gets render in every route in react

I'm new to react I'm using react-router ^6.0.2 and my problem is I created a component for the router then I called this component in the index file but when I add another component to the index it gets rendered in all the routes with the navbar in every single route I want the navbar to be rendered in all components but not the other component in the index file sorry for my bad English

index file:

import React from "react";
import  ReactDOM  from "react-dom";
import "../src/css/style.css";
import Router from "./Components/Router";

const App =()=>{ 
return(
    <div> 

 <Router/>  {/* i want this to get renderd in all routes */}
 <Test/> {/*i want this to get renderd only in home page  */}

</div>

)
}

ReactDOM.render(<App/>,document.getElementById("root"));

router component :

import { Component } from "react";
import  ReactDOM  from "react-dom";
import { BrowserRouter,  Routes, Route}  from "react-router-dom";
import NavBar from "./NavBar";
import About from "./About";
import Product from "./Product"
import Sp from "./Sp"
import Contact from "./Contact"






 class Router extends Component{
render(){
    return(

        <BrowserRouter>

        <NavBar/>
       <Routes>
       <Route path="about" element={<About/>}/>
       <Route path="product" element={<Product/>}/>
       <Route path="sp" element={<Sp/>}/>
       <Route path="contact" element={<Contact/>}/>
       </Routes>
       
       </BrowserRouter>
    )
}
}
 export default Router
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As it is right now, you don't have a home page. A home page is essentially a <Route path='/' /> Make one, and put your <Test/> component in it. Let me know if you're still struggling.

about 4 years ago · Juan Pablo Isaza Report

0

Put test component in routes component and send it's path as "home"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!