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

86
Visualizações
How to use different kinds of navbar components on different pages

I have two different navbar components created for two different subsystems of our project.

App.js

function App() {
  return (
    <>
      <Router>
        <Routes>
          <Route path="/" element={<CirclePage />} />
          <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 />} />
                  <Route path="/contact" element={<Contact/>}/>
                </Routes>
              </>
            }
          />

          <Route 
            path = "*"
            element={
              <>
                <NavbarClub/>
                <Routes>
                  <Route path="/homepage-club" element={<HomepageClubs />} />
                  <Route path="/events-club" element={<EventManagement />} />
                  <Route path="/contact-clubs" element={<ContactClubs />} />
                  <Route path="/notifications-club" element={<NotificationsClub />} />
                  <Route path="/profile-club" element={<ClubProfile />} />
              </Routes>
              </>
            } 
            />

        </Routes>
      </Router>
    </>
  );
}

export default App;

Navbar is visible on every screen except the main screen CirclePage. I want Navbar to be visible on homepage, events, clubs, notifications, profile and contact while NavbarClub to be visible in with the -club pages. How can I implement this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Create layout wrapper components for each that renders the specific navbar and an Outlet for nested Route components.

Example:

import { Outlet } from 'react-router-dom';

const NavbarLayout = () => (
  <>
    <Navbar />
    <Outlet />
  </>
);

const NavbarClubLayout = () => (
  <>
    <NavbarClub />
    <Outlet />
  </>
);

App

function App() {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<CirclePage />} />
        <Route path="*" element={<NavbarLayout />}>
          <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 />} />
          <Route path="contact" element={<Contact />} />
        </Route>

        <Route path="*" element={<NavbarClubLayout />}>
          <Route path="homepage-club" element={<HomepageClubs />} />
          <Route path="events-club" element={<EventManagement />} />
          <Route path="contact-clubs" element={<ContactClubs />} />
          <Route path="notifications-club" element={<NotificationsClub />} />
          <Route path="profile-club" element={<ClubProfile />} />
        </Route>
      </Routes>
    </Router>
  );
}

Edit how-to-use-different-kinds-of-navbar-components-on-different-pages

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