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.

Page is refreshed by calling history.go(), while history.back() isn't

See original GitHub issue

We have iframe based micro-frontends. There is a need of changing the state of the inside app from outside one without full-reloading of the inside one. There is <BrowserRouter /> which uses Native History API.

I have tested the behavior on single app without any iframes.

When I click anchors in the app, React router doesn’t refresh the whole app, and replaces parts of the app. In my case – it’s pagination.

I can call window.history.back() and it will not trigger page refresh. The same, I can do window.history.go(-1) and it will not trigger page referesh.

Then I decided what if I make window.history.pushState(null, null, 'page/2') and call window.history.go() – page will be refreshed from scratch.

I can solve my task by replacing BrowserRouter by Router and exposing history object to window.ReactRouterHistory, but I think it’s too much, when I can do window.history.back() without a page refresh.

Is it a bug? Why the page is fully refreshed by go(), but isn’t when go(-1)? Is there a proper way to do this?

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
StringEpsiloncommented, Aug 5, 2020

Unfortunatly, there is no API to get notified about window.history.pushState() and window.history.replaceState(), as the browser will only fire onpopstate when the user navigates.

This library would need to monkeypatch the two functions to add in events or a callback.

1reaction
StringEpsiloncommented, Aug 5, 2020

History version 5 has support for custom window objects to enable easier use of iframes (see #624 ). I’m afraid you just have to wait for react-router version 6 to come out or risk the beta.

Also, I think you should probably seek advice on stackoverflow and or reactiflux on this. https://www.reactiflux.com/ This is clearly a support question and not a feature request or bug report.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows.history.back() + location.reload() jquery
On success in the ajax request, i use windows.history.back() to go to the previous page ans here i want to refresh this page,...
Read more >
How to go back one page and refresh with JavaScript
If there is, we navigate to that page. If there isn't, we fall back to using history.back() as an alternative, which sends the...
Read more >
Refresh the Page in JavaScript – JS Reload Window Tutorial
The History function is another method for refreshing a page. The history function is used as usual to navigate back or forward by...
Read more >
History.pushState() - Web APIs | MDN
The state object is a JavaScript object which is associated with the new history entry created by pushState() . Whenever the user navigates...
Read more >
Preserving Form State in Refreshes and Navigation with React
Using window.history.back() is a handy way to go back ... Now I could use the history state in the next page just by...
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