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

133
Vistas
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 Respuestas
Responde la pregunta

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 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