Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh <Redirect to='/...'> react

I'm having a ton of difficulty finding the answer. Right now all my

<Route exact path='/' render={()=><Redirect to='/dashboard'/>}/>

does is change the url to ".../dashboard", but it doesn't refresh the page so that the component loads, only when I hit refresh does my component load.

How can I get <Redirect ... /> to refresh the page after redirect?

I have had success with window.location.reload(), but I don't know how to put it in. I've also tried adding <Redirect push to=.../> without luck.

like image 391
Kevin Danikowski Avatar asked Feb 23 '26 18:02

Kevin Danikowski


1 Answers

setup a switch route and a Redirect component

    <Switch>
      <Redirect from='/' to='/dashboard'/>
      <Route path='/dashboard' render={(props) => (
    auth.isAuthenticated === true
      ? <Component {...props} />
      : <Redirect to='/login' />
  )} 
/>
</Switch>

More on the docs

like image 134
ztadic91 Avatar answered Feb 26 '26 07:02

ztadic91



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!