简体   繁体   English

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

[英]How to handle dynamic URL routing in Firebase hosting

So let's say in my public folder in Firebase i have an index.html and a salon.html . 所以,假设我在Firebase的公共文件夹中有一个index.html和一个salon.html

Now for a url like xyz.com/salon/43 I want to load salon.html and in the javascript I want to fetch salon 43 from the realtime database. 现在,对于像xyz.com/salon/43这样的网址,我想加载salon.html ,在javascript中,我想从实时数据库中获取沙龙43。

Right now I'm able to have urls like xyz.com/salon?id=43 . 现在我可以拥有像xyz.com/salon?id=43这样的网址。 I'm wondering if it is possible to do the former in Firebase hosting and if so how. 我想知道是否有可能在Firebase托管中做前者,如果是这样的话。

You're looking for Firebase Hosting rewrites . 您正在寻找Firebase Hosting 重写 From the documentation : 文档

Use a rewrite when you want to show the same content for multiple URLs. 如果要为多个URL显示相同的内容,请使用重写。 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. 重写对于模式匹配特别有用,因为您可以接受与模式匹配的任何URL,并让客户端代码决定要显示的内容。 Rewrite rules can be used to support apps using HTML5 pushState for navigation. 重写规则可用于支持使用HTML5 pushState进行导航的应用程序。 When a browser attempts to open a specified source URL it will be given the contents of the file at the destination URL. 当浏览器尝试打开指定的源URL时,将在目标URL处为其提供该文件的内容。

URL rewrites can be specified by defining a rewrites section within hosting in the firebase.json file: 可以通过在firebase.json文件中的托管中定义rewrites部分来指定URL重写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM