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.

React-router history pushes / replaces not triggering webview events unless links are clicked twice

See original GitHub issue

Bug description:

On Android, when navigating on our React web app, running inside a react-native-webview, no navigation events are triggered, unless you click the link twice. Adding the workarounds previously found in Guide.md (shimming the history methods) works, but I was under the impression this shouldn’t be necessary. The page I’m working with doesn’t use react-router directly but it uses the same underlying library (ReactTraining/history) and I can confirm the problem exists with react-router as well.

To Reproduce:

Load this codesandbox (it’s one of the react-router demo pages): https://bnpsd.csb.app/ in a react-native-webview Click around

Expected behavior:

Navigation events (like onNavigationStateChange) are called.

Environment:

  • OS: Android
  • OS version: 9 / 10
  • react-native version: 0.61.4
  • react-native-webview version: 8.0.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

5reactions
maximilizecommented, Sep 26, 2022

This problem is not solved. Can this issue be opened again?

2reactions
cbotsikascommented, Feb 1, 2022

Although this is an old thread, maybe it’s helpful for others. It appears that onNavigationStateChange is not called on Android when the app uses history pushState and popState when navigating back in history. On iOS it is being called just fine. I noticed that onLoadProgress is called in both platforms so what I did was to use both like this:

      onNavigationStateChange={(navState) => {
        // On Android if the page uses history pushState and popState,
        // onNavigationStateChange is not called but onLoadProgress does
        setCanGoBackInWebView(navState.canGoBack);
      }}
      onLoadProgress={(syntheticEvent) => {
        const { nativeEvent } = syntheticEvent;
        // On Android if the page uses history pushState and popState,
        // onNavigationStateChange is not called but onLoadProgress does
        setCanGoBackInWebView(nativeEvent.canGoBack);
      }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-router history pushes / replaces not triggering webview ...
On Android, when navigating on our React web app, running inside a react-native-webview, no navigation events are triggered, unless you click ...
Read more >
React history.push() is updating url but not navigating to it in ...
Once your custom history object is passed in via Router's history prop, history.push should work just as expected in anywhere of your app....
Read more >
React Navigation - Ionic Framework
The React Navigation guide covers routing in an app built with Ionic and React. Learn to define a redirect path for router links...
Read more >
Interact programmatically with the Navigation component
The Navigation component provides ways to programmatically create and interact with certain navigation elements.
Read more >
Framework7 Release Notes
Router. Fixed swipe-back issues on iOS 14. Device. Fixed iOS detection for newest iPads. Svelte. ListInput, Input. Fixed not working TextEditor events.
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