Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 663 Bytes

clear-react-routers-location-state-from-the-console.md

File metadata and controls

30 lines (24 loc) · 663 Bytes

Clear React Router's Location State From the Console

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

Window.history docs