Set start_url in web app manifest based on the URL that was added to homescreen

妖精的绣舞 提交于 2021-02-08 14:56:33

问题


My site has several subsections. When a user adds the site to their homescreen, I'd like to make sure that the home screen icon launches them into the subsection they were on when they added to homescreen.

I can register a different manifest for each subsection, but this doesn't work for single page apps where there's no page reload. I'm considering storing the subsection in a cookie and then redirecting from a generic start URL based on that cookie.

Is there a better way to do this?


回答1:


If you remove the start_url from the manifest.json file then it will default to the page user was browsing while adding pwa app to homescreen. ref : https://developers.google.com/web/tools/lighthouse/audits/manifest-contains-start_url




回答2:


Have you tried changing the web app manifest url when the user navigates between different subsections?

document.querySelector('link[rel=manifest]').href = '/example-manifest.json';



回答3:


One solution is for each page do you have a separated manifest with attribute start_url specific to each page.



来源:https://stackoverflow.com/questions/39495573/set-start-url-in-web-app-manifest-based-on-the-url-that-was-added-to-homescreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!