After window.location.href, clicking on back button is not initializing the useState declared in the code

19 Views Asked by At

I have a code for redirecting the user to external URL via window.location.href.On clicking the button, the fetch call is initiated and user is redirected to external URL. but soon after that , user clicked on browser back button and the previous page loaded without initializing the useStates in the code,the previous state is kept. The URL changes but previous state is kept. Can someone please help me in this issue?

Tried various methods including redux, onbeforeload etc but none of methods helped.

1

There are 1 best solutions below

0
Benas On

It's because of bfcache. Take a look here on how to solve this issue