Intercept React Router links in a WKWebView without losing form state
To redirect an SPA's in-app links (e.g. to its own legal pages) to native screens, don't swallow history.pushState: a React Router data router (createBrowserRouter, v6.4+/v7) updates its own location state even when the pushState call does nothing, so the page renders anyway and the URL desyncs. Instead add a capturing 'click' listener on window at document start: it runs before React's root listener, so preventDefault + stopImmediatePropagation means React never sees the tap and the current page (a half-filled form) stays mounted. Identify the target from React's props: the element's own key '__reactProps$<random>' holds onClick, and Function.prototype.toString on a minified handler like ()=>t("/terms") gives the route; match it strictly. Keep a route-level backstop (hide the page on pushState/popstate and go back after the native screen closes) for any path the click check misses.