question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prompt not working as intended for history.push and browser back button

See original GitHub issue

Version

5.2.0

Steps to reproduce

We are using Prompt for history.push and browser back button. When we are clicking on either of them, and then click on Cancel, the url first changes to new url. Then it gets back to previous url, but the state is reset. Due to this, we are losing the progres.

Expected Behavior

By clicking on cancel, the state should not get reset, it should maintain itself. While only when we click on OK, state should reset and view should be forwarded to new view (according to url).

Actual Behavior

State is getting reset, with url being changed even though we are clicking on cancel.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

1reaction
myNameIsDucommented, Jun 11, 2021

If you use window.history.go, you will have the problem of switching between old and new URLs. The browser will display the new URL, but inside the React -Router, it is still the old URL, so its state is old

0reactions
myNameIsDucommented, Sep 25, 2021

Hi, I am facing the same issue.

Proposed solution in: #7865 (comment)

Do not use window.history

Result I’ve tried to avoid relying on window.history but it doesn’t bypass the problem.

I really believe this has to be fixed. Since it’s a real issue in react-router.

Demo reproducing the issue

I was able to put together a demo which reproduces the bug: https://stackblitz.com/edit/react-ts-qfjexz Follow the steps on the right side and keep note of current url (in the embedded browser window)

I think you can this:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router v4 this.props.history.push(...) not working
So I came to this question hoping for an answer but to no avail. I have used const { history } = this.props;...
Read more >
5.4 Session history and navigation — HTML5 - W3C
When the user navigates through a browsing context, e.g. using a browser's back and forward buttons, the user agent must traverse the history...
Read more >
Designing A Better Back Button UX - Smashing Magazine
We've all been in a situation when a browser's “Back” button just didn't work as expected, driving us away from the goal, ...
Read more >
Handling common JavaScript problems - MDN Web Docs
As we said in the previous article on HTML/CSS, you should make sure your code is working generally, before going on to concentrate...
Read more >
Disabling back button in React with react-router v5 - Ye Joo Park
Create a top-level <Route> in <BrowserRouter> that matches all URLs ( / ) and render App component. · Get history object by wrapping...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found