Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!