Firebase CLI:“配置为单页应用程序(将所有URL重写为/index.html)" [英] Firebase CLI: "Configure as a single-page app (rewrite all urls to /index.html)"
本文介绍了Firebase CLI:“配置为单页应用程序(将所有URL重写为/index.html)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚使用Firebase CLI初始化了一个静态托管项目.启用配置为单页应用程序"选项时,会发生什么情况?我正在寻找有关确切修改了哪些文件的说明,以及这对Firebase后端的影响.
I just used the Firebase CLI to init a static hosting project. What exactly happens when you enable the "configure as a single-page app" option? I'm looking for a description of exactly which files are modified, and what kind of effect this has on the Firebase backend.
推荐答案
该选项只是在firebase.json
文件中设置一个标志,即可将所有URL重定向到/index.html
.
That option simply sets a flag in the firebase.json
file to redirect all URLs to /index.html
.
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
有关更多信息,请参见 Firebase托管文档,该信息也包含以下完整示例:
See the documentation of Firebase Hosting for more information, which also contains this fuller example:
"hosting": {
// ...
// Add the "rewrites" attribute within "hosting"
"rewrites": [ {
// Serves index.html for requests to files or directories that do not exist
"source": "**",
"destination": "/index.html"
}, {
// Serves index.html for requests to both "/foo" and "/foo/**"
// Using "/foo/**" only matches paths like "/foo/xyz", but not "/foo"
"source": "/foo{,/**}",
"destination": "/index.html"
}, {
// Excludes specified pathways from rewrites
"source": "!/@(js|css)/**",
"destination": "/index.html"
} ]
}
这篇关于Firebase CLI:“配置为单页应用程序(将所有URL重写为/index.html)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文