URL 中的 Firebase 托管路径参数不起作用

Din*_*uka 2 url-rewriting firebase firebase-hosting

id在 firebase 上托管时,我需要通过使用路径参数从 URL 中获取动态内容来提供动态内容。例如:

mydomain.com/apps/4480023

在这种情况下,我想提取4480023作为我正在寻找的资源的 ID。我在 firebase.json 文件中尝试了以下更改:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/apps/**",
        "destination": "/apps.html"
      }
    ],
    "cleanUrls": true
  }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,当用户浏览到该资源时,我可以使用 javascript 函数从 URL 中检索 ID。我的问题是,这种重写不起作用,它会将用户定向到 index.html 页面,并且所有 CSS/JS 文件最终都无法正常运行。

如何修改它以启用此功能?

Dou*_*son 5

按顺序检查重写。这意味着匹配所有请求的第一次重写总是由 index.html 提供服务。

您所要做的就是更改重写的顺序,以允许/apps/**/**捕获其他所有内容之前进行匹配。

"rewrites": [
  {
    "source": "/apps/**",
    "destination": "/apps.html"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]
Run Code Online (Sandbox Code Playgroud)