The return of React Router's useLocation
hook has a key called state
which
contains values passed during a redirect or navigation. But where is that state
stored by the browser, and how do we clear it?
I found it in Chrome on window.history.state
:
> window.history.state
<
{
"usr": {
"pageTitle": "Redirected!"
},
"key": "31ytq582",
"idx": 4
}
And cleared it using replaceState
:
> window.history.replaceState({}, '')
< undefined
> window.history.state
< {}