remove react router dom state on refresh code example

Example 1: react router remove location state on refresh

import createHistory from 'history/createBrowserHistory'

...

componentDidMount(){
    const history = createHistory();
    if (history.location.state && history.location.state.transaction) {
        let state = { ...history.location.state };
        delete state.transaction;
        history.replace({ ...history.location, state });
    }
}

Example 2: remove state from location on page load in react router dom

history.replace('', null);