Skip to content

Commit

Permalink
Proposed fix for ZacharyRSmith#2
Browse files Browse the repository at this point in the history
Proposed fix for ZacharyRSmith#2
  • Loading branch information
piotr-cz committed Sep 30, 2018
1 parent 5ffade2 commit 5012d5e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,31 @@ class NavigationPrompt extends React.Component<PropsT, StateT> {
navigateToNextLocation(cb) {
let {action, nextLocation} = this.state;
action = {
'POP': 'push',
'POP': 'goBack',
'PUSH': 'push',
'REPLACE': 'replace'
}[action || 'PUSH'];
if (!nextLocation) nextLocation = {pathname: '/'};
const {history} = this.props;

this.state.unblock();

if (action === 'goBack') {
history.goBack();
this._prevUserAction = 'CONFIRM';
// This helps when using in goBack
window.setTimeout(() => {
// There is a change that component has been unmounted after navigation
if (this.isMounted) {
this.setState({
...initState,
unblock: this.props.history.block(this.block)
}); // FIXME? Does history.listen need to be used instead, for async?
}
}, 0)
return
}

// $FlowFixMe history.replace()'s type expects LocationShape even though it works with Location.
history[action](nextLocation); // could unmount at this point
this._prevUserAction = 'CONFIRM';
Expand Down

0 comments on commit 5012d5e

Please sign in to comment.