3
votes

I'm trying to detect when the page location changes in a react app using the Xamarin forms webview .Navigated event. However, it seems like it's only issued when I navigate to an external page, not within the react app, even though I'm using react router. In my browser, the url changes but the Xamarin webview doesn't register that change, even if I manually poll the url by printing webView.Source.

Is there some way I can detect a navigation within the react app from C#?

1
What are your urls in react app? Are they hash based? - Nagaraj Tantri
They're just static urls using the react router switch statement, e.g. localhost:3000/page-1. Based on the example at github.com/mlaursen/react-md/tree/master/examples/… - Daniel Centore
you ever find a solution for this? - shreddish
@shreddish I don't think I did. I ended up abandoning embedding reactjs withing a Xamarin forms app and instead built this app from scratch using the underlying APIs instead, and this was one of multiple reasons for doing that. - Daniel Centore

1 Answers

-1
votes

If you want a component to be location aware, you can wrap it with the HoC withRouter provided by React Router.

You can get access to the history object’s properties and the closest <Route>'s match via the withRouter higher-order component. withRouter will re-render its component every time the route changes with the same props as render props: { match, location, history }.

Once you're getting location change updates in your react app you can update your C# to perform any actions you require.

EDIT: To address your comment...

Now I've never used C#, but according to my research this should work.... take a look at __doPostBack. You can read about how to use it here.