javascript - 如何在 Firebase 托管中处理动态 URL 路由

标签 javascript firebase frontend firebase-hosting

因此,假设在 Firebase 的公用文件夹中,我有一个 index.htmlsalon.html .

现在获取像 xyz.com/salon/43 这样的网址我要加载salon.html在 javascript 中,我想从实时数据库中获取沙龙 43。

现在我可以拥有像 xyz.com/salon?id=43 这样的网址.我想知道是否可以在 Firebase 托管中进行前者,如果可以的话。

最佳答案

您正在寻找 Firebase 托管重写。来自 documentation :

Use a rewrite when you want to show the same content for multiple URLs. Rewrites are particularly useful with pattern matching, as you can accept any URL that matches the pattern and let the client-side code decide what to display. Rewrite rules can be used to support apps using HTML5 pushState for navigation. When a browser attempts to open a specified source URL it will be given the contents of the file at the destination URL.

URL rewrites can be specified by defining a rewrites section within hosting in the firebase.json file:

"hosting": {
  // Add the "rewrites" section within "hosting"
  "rewrites": [ {
    "source": "**",
    "destination": "/index.html"
  } ]
}

关于javascript - 如何在 Firebase 托管中处理动态 URL 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44261372/

相关文章:

android - 如何使用它的 child 在 recyclerview 中显示来自 firebase 的特定数据?

node.js - 使用 Webpack 编译 Scss

html - 如何在div的底部和中心放置一个按钮?

javascript - Javascript 的 date() 函数中的日期数是什么意思?

javascript - 获取上传的文件/图像的名称

JavaScript/jQuery : Unable to get proper keyCode when capsLock is ON

firebase - 错误:获取存储源时出错:generic::unknown... 当通过 GitHub Actions 部署 GCP Cloud Function 时

javascript - 无法加载 firebase(重定向错误)

javascript - 如何使用 jQuery 设置 BootStrap 输入组的内容?

angular - 下拉列表不会填充 Angular 中的 API 数据