From af559d2e1bbd15ae6c50aede8244225fa3272a1a Mon Sep 17 00:00:00 2001 From: "Zachary R. Smith" Date: Wed, 25 Oct 2017 17:46:10 -0400 Subject: [PATCH] fix: When action is `"POP"`, push We cannot know the correct history entry to pop to without using memory history (https://github.com/ReactTraining/history#properties). --- es/index.js | 8 ++------ package.json | 2 +- src/index.js | 8 ++------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/es/index.js b/es/index.js index 3bc8065..537f099 100644 --- a/es/index.js +++ b/es/index.js @@ -1909,7 +1909,7 @@ var NavigationPrompt = function (_React$Component) { nextLocation = _state.nextLocation; action = { - 'POP': 'goBack', + 'POP': 'push', 'PUSH': 'push', 'REPLACE': 'replace' }[action || 'PUSH']; @@ -1918,11 +1918,7 @@ var NavigationPrompt = function (_React$Component) { this.state.unblock(); - if (action === 'goBack') { - history.goBack(); - } else { - history[action](nextLocation.pathname); - } + history[action](nextLocation.pathname); this.setState(_extends({}, initState, { unblock: this.props.history.block(this.block) }), cb); // FIXME? Does history.listen need to be used instead, for async? diff --git a/package.json b/package.json index dc102c5..859eec4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-router-navigation-prompt", - "version": "1.5.0", + "version": "1.5.1", "description": "A replacement component for the react-router ``. Allows for more flexible dialogs.", "scripts": { "build": "webpack", diff --git a/src/index.js b/src/index.js index c118894..d404fec 100644 --- a/src/index.js +++ b/src/index.js @@ -76,7 +76,7 @@ class NavigationPrompt extends React.Component { navigateToNextLocation(cb) { let {action, nextLocation} = this.state; action = { - 'POP': 'goBack', + 'POP': 'push', 'PUSH': 'push', 'REPLACE': 'replace' }[action || 'PUSH']; @@ -84,11 +84,7 @@ class NavigationPrompt extends React.Component { const {history} = this.props; this.state.unblock(); - if (action === 'goBack') { - history.goBack(); - } else { - history[action](nextLocation.pathname); - } + history[action](nextLocation.pathname); this.setState({ ...initState, unblock: this.props.history.block(this.block)