【问题标题】:Firebase Hosting Path Parameters in URL Not WorkingURL 中的 Firebase 托管路径参数不起作用
【发布时间】:2018-10-20 06:32:22
【问题描述】:

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

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
  }
}

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

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

【问题讨论】:

  • 可以分享一下firebase.json排序后如何提取param的代码
  • @Hanzala 你的意思是查询参数吗?喜欢:website.com?user=2

标签: firebase url-rewriting firebase-hosting


【解决方案1】:

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

您所要做的就是改变重写的顺序,让/apps/** 有可能在/** 捕获其他所有内容之前进行匹配。

"rewrites": [
  {
    "source": "/apps/**",
    "destination": "/apps.html"
  },
  {
    "source": "**",
    "destination": "/index.html"
  }
]

【讨论】:

  • 没想到会导致这个问题。谢谢:)
猜你喜欢
  • 1970-01-01
  • 2021-11-04
  • 2020-07-14
  • 2013-07-06
  • 1970-01-01
  • 2020-10-02
  • 2016-04-18
  • 2020-08-18
  • 1970-01-01
相关资源
最近更新 更多