A hacky solution I've implemented here is to silently change the URL on the page you prompt the user to install the PWA with: history.pushState({}, "", "/");
(see: https://mcmap.net/q/321180/-silently-update-url-without-triggering-route-in-vue-router)
This will update the URL but won't cause the page to reload or refresh the DOM, so you can see the page you're on as normal, but when the user goes to install the PWA (Add to home screen
) it'll save the root URL, so that's what they'll see when they open the PWA.
Downsides here include:
- the URL in the address bar will update (not a big deal on mobile)
- if the user presses the back button they'll go "back" to the page you triggered the
history.pushState()
on, so they'll need to press back twice to actually go back
- if the user refreshes the page they'll see the homepage
In my use case this is good enough, there might be extra solutions to handle these issues that could be applied on top of this solution to improve UX.