firebase - URL 中的 Firebase 托管路径参数不起作用
问题描述
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
}
}
在这种情况下,当用户浏览该资源时,我可以使用 javascript 函数从 URL 中检索 ID。我的问题是,这种重写不起作用,它将用户引导到 index.html 页面,并且所有 CSS/JS 文件最终都无法正常运行。
如何修改它以启用此功能?
解决方案
按顺序检查重写。这意味着匹配所有请求的第一次重写将始终由 index.html 提供服务。
您所要做的就是更改重写的顺序,以便在捕获其他所有内容/apps/**
之前有可能进行匹配。/**
"rewrites": [
{
"source": "/apps/**",
"destination": "/apps.html"
},
{
"source": "**",
"destination": "/index.html"
}
]
推荐阅读
- node.js - Joi 验证 - 如何验证仅需要一个对象而不需要另一个对象的对象数组
- docker - 使用 API 和服务帐户 JSON 文件从 Google Container Registry 读取
- tableau-api - 如何在 tableau 中获取减法结果的详细信息
- android - 如何在 Android Kitkat 版本(API 19)中更改 android 应用程序的语言?
- android - 警报管理器 setRepeat 中的问题
- powershell - 测试路径的问题
- excel - 在工作表上添加行时如何在宏中保持正确的单元格引用
- azure - 如何连接到虚拟机内的本地 Oracle 数据库?
- excel - 类属性错误“需要对象”,但工作正常
- python - Django:如何构建食堂菜单预订系统以避免共现预订?