Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform back from browser, but onConfirm didn't perform back #2

Closed
tumor800 opened this issue Nov 28, 2017 · 10 comments · Fixed by #39
Closed

Perform back from browser, but onConfirm didn't perform back #2

tumor800 opened this issue Nov 28, 2017 · 10 comments · Fixed by #39

Comments

@tumor800
Copy link

tumor800 commented Nov 28, 2017

I'm trying to perform action back via browser navigation and <NavigationPrompt/> triggered.
But when I click button that have onClick={onConfirm}, it not actually back, but it's forwarded.
I expected the program run history.goBack()

do you have any solution for this?
could you create props when able to check backward or forward action?

my code:

<NavigationPrompt when={(crntLocation, nextLocation) => nextLocation.pathname.startsWith('/movies/schedules')}> 
  {({ isActive, onConfirm, onCancel }) => (
    <Popup
      title="Your Data will be Lost"
      visible={isActive}
      buttons={[<Button primary onClick={onConfirm}>Ok</Button>, <Button outline onClick={onCancel}>Cancel</Button>]}
    >Are you sure you want to leave this page?</Popup>
  )}
</NavigationPrompt>

are you do typo in this part?


  navigateToNextLocation(cb) {
    let {action, nextLocation} = this.state;
    action = {
      'POP': 'push', // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this part
      'PUSH': 'push',
      'REPLACE': 'replace'
    }[action || 'PUSH'];
    if (!nextLocation) nextLocation = {pathname: '/'};
    const {history} = this.props;

    this.state.unblock();
    history[action](nextLocation.pathname);
    this.setState({
      ...initState,
      unblock: this.props.history.block(this.block)
    }, cb); // FIXME?  Does history.listen need to be used instead, for async?
  }
@ZacharyRSmith
Copy link
Owner

No, that was not a typo. I originally used pop, but due to issues with that I went to push.

You can read more in my commit message here: af559d2

If user has this in their history:

  1. /1/path/ago
  2. /2/paths/ago

and right click on back arrow and clicks on /2/paths/ago, then pop() would take them to /1/path/ago instead of /2/paths/ago

ZacharyRSmith referenced this issue Nov 30, 2017
We cannot know the correct history entry to pop to without using memory history
(https://github.com/ReactTraining/history#properties).
@ZacharyRSmith
Copy link
Owner

ie, supporting pop would require a version of <NavigationPrompt/> that requires memory history. i would like to make that version of <NavigationPrompt/>, maybe this weekend?

@GlebDolzhikov
Copy link

GlebDolzhikov commented Jan 19, 2018

I have i little bit similar issue, i try to perform back, but onConfirm do nothing in that case.
More then that i get this warn:
Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack

PS: I use hash navigation.

@piotr-cz
Copy link
Contributor

piotr-cz commented Jun 5, 2018

I'm using this library inside a PWA.
When user taps on back button, there is a confirmation dialog asking if he/she wants to abandon edits.

Generally in mobile browsers tapping back button rewinds the history to the point when there are no previous entries and then the page tab/ PWA is closed.

The problem with adding new history entry after tapping back button is user is not able to exit the PWA (think close page tab) with back button app.
Instead of history shrinking on confirm there is new entry coming up.

@ZacharyRSmith
Copy link
Owner

ty for reporting this, @piotr-cz . please make a PR fixing this if you can!

@piotr-cz
Copy link
Contributor

piotr-cz commented Jun 6, 2018

I've tried to switch push to goBack method, here as a revert of af559d2 but that didn't work

I'll work on it later

@piotr-cz
Copy link
Contributor

piotr-cz commented Jun 6, 2018

Can you elaborate on your commit message We cannot know the correct history entry to pop to without using memory history ?

piotr-cz added a commit to piotr-cz/react-router-navigation-prompt that referenced this issue Jun 6, 2018
@piotr-cz
Copy link
Contributor

piotr-cz commented Jun 6, 2018

Everybody, please test and comment on #30

@ZacharyRSmith
Copy link
Owner

@piotr-cz ,

Re: "We cannot know the correct history entry to pop to without using memory history" -- Here is an example:

If user has this in their history:

/1/path/ago
/2/paths/ago

and right click on back arrow and clicks on /2/paths/ago, then pop() would take them to /1/path/ago instead of /2/paths/ago

I think supporting pop would require a version of that uses memory history

@piotr-cz
Copy link
Contributor

Back button should work now (as some of us expect it to), when using new allowGoBack={true} option.
For implementation details see #39, for option details see README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants