Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda