Firebase CLI:“配置为单页应用程序(将所有URL重写为/index.html)”

问题描述 投票:25回答:3

我刚刚使用Firebase CLI来初始化静态托管项目。启用“配置为单页应用程序”选项时会发生什么?我正在寻找一个关于哪些文件被修改的描述,以及它对Firebase后端的影响。

Screenshot of firebase init command

firebase firebase-hosting firebase-tools
3个回答
51
投票

该选项只是在firebase.json文件中设置一个标志,将所有URL重定向到/index.html

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

有关更多信息,请参阅documentation of Firebase Hosting


18
投票

完整示例:

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

1
投票

官方Firebase说明:

去年我们曾经使用过这个选项(第一季度和第二季度),但它似乎什么也没做,但是现在我们应用它时,肯定会有很大的不同。这里有完整的官方解释:

https://firebase.google.com/docs/hosting/url-redirects-rewrites#section-rewrites

在同一页面的下一部分中甚至还有一些关于标题使用的有用信息。


0
投票

注意:如果您想要服务器端渲染(SSR),请键入No并设置您的rewrites如下:

"rewrites": [
  {
    "function": "angularUniversalFunction",
    "source": "**"
  }
]

毕竟,无论你选择什么,你总是可以在firebase.json文件中更改它。

© www.soinside.com 2019 - 2024. All rights reserved.