PWABuilder
PWABuilder copied to clipboard
[Docs][iOS] Deep links/shortcuts/scheme links and SPAs
This is a docs suggestion. I've been investigating these features for the past day and in addition to https://github.com/pwa-builder/pwabuilder-ios/pull/47 I'd like to make the following suggestion.
SPAs will reload when window.location.href is set to a different URL because of the way router libraries work. For react-router-dom users (and probably very similar for users of other environments), you can use something similar to the following.
In place of
PWAShell.webView.evaluateJavaScript("location.href = '\(universalLink)'")
you can use
PWAShell.webView.evaluateJavaScript("window.routerPush !== undefined ?
// adjust URL to match router requirements - react-router-dom only wants the path
window.routerPush('\(universalLink)'.replace('https://mypwa.domain.com',''))
: window.location.href = '\(universalLink)'")
// line breaks added for readability
In your SPA, you place a small component within your router component tree
<BrowserRouter>
<ExposeHistory />
</BrowserRouter>
where ExposeHistory is
function ExposeHistory() {
// react-router-dom v5 - I think you just change the hook to useNavigate with v6
const history = useHistory();
useEffect(() => {
if (history !== undefined && window.routerPush === undefined) {
window.routerPush = history.push;
}
}, [history]);
return null;
}
This makes the router libraries history abstraction available in the window scope where our Swift apps can easily call a function to push a new path!
Hello justrealmilk, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will investigate the issue and help solve it ASAP. Other community members may also look into the issue and provide feedback 🙌
This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.
This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.
This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.
This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.
cc @zateutsch for visibility