有没有办法将 PWA/TWA 应用程序放入子域

Is There a Way To Put a PWA/TWA App in a Sub-Domain

我正在尝试将 Progressive Web Apps 添加到我的服务器。我不想为每个应用程序创建一个新网站。我的偏好是将每个应用程序添加到这样的网站的子域中:www.example.com/app1

问题是当我 运行 这里的语句列表生成器时:https://developers.google.com/digital-asset-links/tools/generator

仅当我在此处放置 assetlinks.json 时才有效:www.example.com。如果是这样的话,那么我只能在 www.example.com 中拥有一个应用程序。我试过在此处放置 assetlinks.json 1) www.example.com/app1 2) www.example.com/app1/.well-known 和 3) www.example。 com。唯一有效的是#3。

还向 androidmanifest.xml 添加了以下意图过滤器,但它不起作用:

<intent-filter android:label="@string/app_name" android:autoVerify="true" >
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <!-- Edit android:host to handle links to the target URL-->
            <data android:scheme="https"
                android:host="example.com"
                android:pathPrefix="/app1" />
</intent-filter>

我无法相信您必须为每个渐进式网络应用程序创建一个不同的网站。有什么建议吗?

这是可以做到的。例如,假设您正在开发 2 个应用程序:

而且,由于这些应用程序将是不同的 TWA,这也意味着每个应用程序将有不同的 package-name:

assetlinks.json 文件应在 https://example.com/.well-known/assetlinks.json 处可用,并且应列出两个应用程序:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app1",
                 "sha256_cert_fingerprints": ["<APP_1_FINGERPRINT>"] }
  }, 
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target" : { "namespace": "android_app", "package_name": "com.example.app2",
                 "sha256_cert_fingerprints": ["<APP_2_FINGERPRINT>"] }
  }

]

每个应用程序都有自己的 asset_statements 声明,将应用程序链接到授权来源:

[{ "relation": ["delegate_permission/common.handle_all_urls"],
   "target": {"namespace": "web", "site": "https://example.com"}}]

需要注意的几件事:

  1. 如果应用程序 1 将打开 https://example.com/app1。但是,如果用户导航到 https://example.com/app2,他们将保留在 full-screen。应用程序 2 导航到 /app1 也是如此。
  2. 应用程序 1 可以启动 TWA 打开 https://example.com/app2,并且 vice-versa。所以,如果你不信任所有的 PWA 和相应的应用程序,不推荐这种方法。

如果以上两项中的任何一项有问题,使用 sub-domains 将是更好的解决方案。