I think I found a workaround
There is onpopstate event:
Calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by performing a browser action, such as clicking on the back button (or calling history.back() in JavaScript), when navigating between two history entries for the same document.
And I checked it: react router saves at state a key property:
On history walking it may contains a data like:
event.state: {key: "jr2go2", state: undefined}
And when we go back to last page on wich we entered the site or app, this state property will be null:
event.state: null
,
So we can handle it with redux + rxjs (for example) like this:
// epic
export const handleHistoryWalkEpic = () =>
fromEvent<PopStateEvent>(window, 'popstate')
.pipe(
map(event => setCanGoBack(!!event.state)),
)
// reducer
case NavigationBarActionsTypes.SET_CAN_GO_BACK:
return {
...state,
canGoBack: action.payload.canGoBack,
}
And you should set canGoBack to true on any push history action, it's possible with your any router handler component:
componentWillUpdate(nextProps: any) {
let { location } = this.props;
if (nextProps.history.action === 'PUSH') {
this.props.setCanGoBack()
}
}