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

263
Visualizações
React navigation bar is in the screen even though it is not on the router

We are trying to implement a react project that has 3 different types of the same application for 3 different purposes. Think of it like the user will choose which to use on the main screen. All 3 types has similar but different page structure, different navbar etc.

I used a router for the main page where they choose which application type they want to go, with path "/", and used different routers for different types for applications because their navbar etc. is different. But the navbar appears in the main screen even while it is not present in the router.

I know it sounds complicated but I will show it with code snippets and screenshots.

App.js

function App() {
  return (
    <>
      <Router>
        <Routes>
          <Route path = "/" exact element={<CirclePage />}/>
        </Routes>
      </Router>

      <Router>
        <Routes>
          <Route path = "/homepage-clubs" exact element={<HomepageClubs />}/>
        </Routes>
      </Router>

      <Router>
        <Navbar/>
        <Routes> 
          <Route path='/homepage' exact element={<Homepage />}/> 
          <Route path='/events' exact element={<Events/>}/>
          <Route path='/clubs' exact element={<Clubs/>}/>
          <Route path='/contact' exact element={<Contact/>}/>
          <Route path='/notifications' exact element={<Notifications/>}/>
          <Route path='/profile' exact element={<Profile/>}/>
        </Routes>
      </Router>
    </>
  );
}
export default App;

Navbar is the navbar I wrote in react.

The home screen is like this atm: application screen at first initialization

I have no clue why there is a navbar below the screen. I may not have understood how really routers work, I am not sure. I need that navbar to go away because every type of application will have a different kind of navbar (I will create different navbars for them) and navbar should not be visible on the main screen. What could be the problem?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are rendering all three routers at the same time, and the third one includes the Navbar component, which is also always rendered. You should use a single router to render all the routes. If you want different layouts for specific routes then you can use a wrapper component to render the Navbar. Render the last set of routes into a generic route that matches anything not more specifically matched, along with the Navbar.

function App() {
  return (
    <>
      <Router>
        <Routes>
          <Route path="/" element={<CirclePage />} />
          <Route path="/homepage-clubs" element={<HomepageClubs />} />
          <Route
            path="*"
            element={
              <>
                <Navbar />
                <Routes>
                  <Route path="/homepage" element={<Homepage />} />
                  <Route path="/events" element={<Events />} />
                  <Route path="/clubs" element={<Clubs />} />
                  <Route path="/notifications" element={<Notifications />} />
                  <Route path="/profile" element={<Profile />} />
                </Routes>
              </>
            }
          />
        </Routes>
      </Router>
    </>
  );
}
about 4 years ago · Santiago Trujillo 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