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

137
Visualizações
React router updates the URL but the route is not being rendered (works after a manual refresh)

These are my public routes

export const PublicRoutes = () => {
    return (
        <Switch>
            <Route path="/" exact component={Login} />
            <Route path={constant.component.logout.url} exact={true}             component={Logout} />
            <Route path={constant.component.register.url} exact= {true} component={SignUp} />
            <Route path={constant.component.forgotPassword.url} exact={true} component={ForgotPassword} />
        </Switch>
    )
}

This is my index.js

ReactDOM.render(
  <React.StrictMode>
    <AlertProvider template={AlertTemplate} {...options}>
      <Router>
        <App />
      </Router>
    </AlertProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

This is my app.js where I am trying to render routes based on accessToken in the local storage

  return (
    <>
      {token ? <DashboardLayout /> : <PublicRoutes />}
    </>
  )

And finally this my dashboard layout where I want the authenticated routes to be shown to the right of the sidebar

        <>
                <SideBar>
                <div className="w-100">
                    <Switch>
                        <Route path="/dashboard" component={Dashboard} />
                        <Route path="/my-account" component={Account} />
                    </Switch>
                </div>
                <Footer>
        </>

Now, when I login, it redirects me to "/dashboard" the url changes but the page shows an empty screen and it works if I refresh the page manually. What am I doing wrong? Thanks

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

0

Are you sure your token is not empty right after you login ? Maybe your token is empty at this moment, PublicRoutes is rendered and that's why the /dashboard route display an empty screen. Maybe your token only gets value after refresh.

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