Chrome (and most other browsers) require you provide the start_url
in the manifest, and it can't be dynamic.
You could build this behaviour by saving the page the user was on when the PWA was installed. Then, set the start_url
to a simple redirect page that checks to see what page the user was on when they installed, and redirect them to that page.
To save the page the user is on when the PWA is installed, listen for the appinstalled
event, then save the page to localStorage:
window.addEventListener('appinstalled', () => {
localStorage['installedFrom'] = window.location.pathname;
});
Then, in the redirect page, do something like:
const installedFrom = localStorage['installedFrom'];
if (installedFrom) {
window.location.replace(installedFrom);
} else {
// No install page saved, send them to the home page?
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…