Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

344
Vistas
how to render same component in every route
import ...

const App = () => {
  const [showModal, setShowModal] = useState(false);
  const toggleModalShow = () => {
    setShowModal(!showModal);
  };

  return (
    <div className="app">
      <Router>
        <ScrollToTop>
          <Routes>
            <Route
              exact
              path="/"
              element={
                <>
                  <Header
                    toggleModalShow={toggleModalShow}
                    showModal={showModal}
                  />
                  <main className="main">
                    <Home />
                  </main>
                </>
              }
            />
            <Route
              path="/games/:game"
              element={
                <>
                  <Header
                    toggleModalShow={toggleModalShow}
                    showModal={showModal}
                  />
                  <GameLobby />
                </>
              }
            />

            <Route
              path="/games"
              element={<PrivateRoute isLoggedIn={isLoggedIn} />}
            >
              <Route
                path="/games"
                element={
                  <>
                    <Header
                      toggleModalShow={toggleModalShow}
                      showModal={showModal}
                    />
                    <Games />
                  </>
                }
              />
            </Route>
          </Routes>
        </ScrollToTop>
      </Router>
    </div>
  );
};

export default App;

Hi all.i want to show <Header /> component in every route but to this i have to use <Header /> component in every <Route />. Is there any way to do that without ? Finally i would be appreciate if you give me feedback about project.

repo : https://github.com/UmutPalabiyik/mook deploy: https://mook-f2b4e.web.app

for testing: username: test pass: 123

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just move the Header above Routes:

return (
    <div className="app">
      <Router>
        <Header
          toggleModalShow={toggleModalShow}
          showModal={showModal}
        />
        <ScrollToTop>
        <Routes>
          <Route
            exact
            path="/"
            element={
              <>
                <main className="main">
                  <Home />
                </main>
              </>
            }
          />
          ...
        </Routes>
        </ScrollToTop>
      </Router>
    </div>
  );
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda