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

327
Visualizações
Page is rendering but not components although everything compiles and styles can be added outside the component

So here is a snippet of code from my App.js,

return (
<div className="app">
  <Router>
    {!user ? (
      <LoginScreen />
    ) : (
      <Switch>
        <Route path='./profile'>
          <ProfileScreen />
        </Route>
        <Route exact path="/">
          <HomeScreen />
        </Route>
      </Switch>
    )}
  </Router>
</div>

Now when I click on the profile button, it takes me to a blank profile page and there are no errors, and everything compiles. Here is the ProfileScreen page code,

import React from 'react'
import './ProfileScreen.css'

function ProfileScreen() {
return (
    <div className='profileScreen'>
        <h1>
            this is the profile screen
        </h1>
    </div>
)
}
 console.log("hello")

export default ProfileScreen

Now the issue here is that every time I refresh the page the console.log("hello") (a test) shows up in developer tools! It also shows up in the main page before I am taken to the profile page. Also in the css file, I can change the entire background color using

* {
   background-color:black;
}

So something is clearly working as I can change the background of the profile page but whenever I target the profileScreen class nothing shows up and my h1 never shows up even without styling when there should be text showing up. I am very new to reactJS and react-router-dom so I would appreciate any help! thank you.

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

0

I'm certain your profile path is incorrect. AFAIK react-router-dom v5 doesn't use relative path routing, it uses absolute path routing, so "./profile" is an invalid path. Update it to be "/profile".

<Switch>
  <Route path="/profile">
    <ProfileScreen />
  </Route>
  <Route exact path="/">
    <HomeScreen />
  </Route>
</Switch>

Edit page-is-rendering-but-not-components-although-everything-compiles-and-styles-can

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