【问题标题】:Wrong page loading by default on firebase link. How do I change the default page that loads? | Firebase hosting默认情况下,firebase 链接上的页面加载错误。如何更改加载的默认页面? | Firebase 托管
【发布时间】:2020-08-13 09:53:34
【问题描述】:

问题

我刚刚建立了火力基地。但是,当我加载 firebase 提供的链接时,它会给我一个“错误 404”。现在我知道该网站已正确托管,因为当我运行本地主机时,我在 url 的末尾输入了以下扩展名:'/html/index.html' - 它工作正常。

但是,firebase 没有找到要加载的正确页面。

当有人访问我的网站时,如何更改默认加载的页面?

为了上下文

我很确定我知道 firebase 在这里做什么。当我第一次运行本地主机时,它运行的是 firebase 提供的默认 index.html。现在我已经删除了默认的 index.html。它不知道在哪里寻找要运行的页面。

我的 index.html 位于公用文件夹中的一个文件夹中。该内部文件夹的名称是 html。

这是文件结构的当前设置,也是我目前解决问题的尝试(基于 Renaud 的建议):

更新

我现在已经实现了以下,但它正在加载 #404

【问题讨论】:

  • 你能分享你在项目目录根目录下的firebase.json文件吗
  • 这就是所有内容:{ "hosting": { "public": "PROJECT ALPHAX", "ignore": [ "firebase.json", "/.*" , "**/node_modules/" ] } }

标签: firebase firebase-hosting


【解决方案1】:

Hosting configuration 的文档中所述,为了将流量重定向到您的index.html 页面(或另一个html 文件),您需要将以下内容添加到@987654324 @ 位于项目目录根目录的文件:

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

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

正如here 解释的那样,“public 属性指定要部署到 Firebase 托管的目录。默认值是名为 public 的目录,但您可以指定任何目录的路径,只要它存在于您的项目目录。”


更新后更新(Firebase 项目文件结构的屏幕截图):

如果我没记错的话,你应该这样做:

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

注意rewriteshosting 之内!

【讨论】:

  • { "hosting": { "public": "PROJECT ALPHAX", "ignore": [ "firebase.json", "/.*", "*/node_modules /" ] }, "rewrites": [{ "source": "*", "destination": "/html/index.html" }] } (我写了这个,还没用不过)
  • 您能否在您的问题中添加 yoru Firebase 项目文件结构的屏幕截图?
  • 对不起,我不确定你是否听懂了最后两个 cmets! :-)“这已经完成”和“不确定你的意思”。我的意思是查看我对答案所做的更新。
  • 如果你做 "public": "PROJECT ALPHAX/html" 怎么办?
  • 我会从一个全新的 Firebase 项目开始,并避免文件夹名称带有空格。我很难再为您提供帮助,因为您似乎对初始文件结构进行了相当多的修改。例如,firebase.json 文件应位于根目录。
猜你喜欢
  • 1970-01-01
  • 2021-08-30
  • 2018-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-26
相关资源
最近更新 更多