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

143
Visualizações
React Component or Elements not showing in Router

So I was trying to make a website with a main page and a login page (and maybe more in the future) in React js.

I have two routes, one route that shows the login screen and another one that shows the main screen.

Now the problem is that the Login component shows, but the MainScreen does not. (When I paste "http://localhost:3000/home/" in the URL bar in the browser, it still shows the Login component)

Here is my code that I have inside App.js:

return (
    <div className="App">
    <Router>    
        <Switch>
          <Route path="/" >
              <LoginScreen />
          </Route>
          <Route path="/home" >
            <MainScreen />
          </Route>
        </Switch>
      </Router>
    </div>
  );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Because the condition of your first rout is being met and rendered.

add EXACT and it should work.

return (
    <div className="App">
    <Router>    
        <Switch>
          <Route exact path="/" >
              <LoginScreen />
          </Route>
          <Route exact path="/home" >
            <MainScreen />
          </Route>
        </Switch>
      </Router>
    </div>
  );
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