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

128
Visualizações
React router - Show only one component (skip default components)

I have a <NotFound /> component which I would like to show if the user goes to the path /404. The only problem is I'd like to show only this component and not the other's such as <Nav /> and <Footer />.

Is there a way I can somehow return if the route is /404 so the other components aren't rendered?

function App() {
  return (
    <>
    <Router>
      // I'd like to show only the <NotFound /> component if path is /404
      // not <Nav /> or the div below.
      <Route path="/404">
            <NotFound />
      </Route>
      <Nav />
      <div className="App">
        <Switch>
          <Route path="/projects">
            <Projects />
          </Route>
          <Route path="/">
            <div className='container'>
              <Header />
              <hr />
              ...
            </div>
          </Route>
        </Switch>
      </div>
      <Footer />
    </Router>
    </>
  );
}

export default App;
almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Render the Nav and Footer on another Switch and Route components. If the path is "/404" then the NotFound component is rendered, otherwise, the "/" route is matched and rendered and the Switch and routes it renders will be matched conditionally as per usual.

Example:

function App() {
  return (
    <Router>
      <Switch>
        <Route path="/404" component={NotFound} />
        <Route path="/">
          <Nav />
          <div className="App">
            <Switch>
              <Route path="/projects" component={Projects} />
              <Route path="/">
                <div className='container'>
                  <Header />
                  <hr />
                  ...
                </div>
              </Route>
            </Switch>
          </div>
          <Footer />
        </Route>
      </Switch>
    </Router>
  );
}
almost 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