如何从单页应用程序重写中排除路径 (/images)?

Dua*_*ane 4 firebase firebase-hosting

我有一个反应应用程序,并且在 firebase 托管中有通常的重写规则:

   "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
Run Code Online (Sandbox Code Playgroud)

我还有一个单独的 /images 目录,其中包含我不想被重写的图像。

如何从重写中排除 /images 目录?

Ger*_*ace 5

我有点晚了,但我在搜索类似问题时发现了这个问题。

使用这个重写规则:

"rewrites": [
  {
    "source": "!/images/**",
    "destination": "/index.html"
  }
]
Run Code Online (Sandbox Code Playgroud)

关键是“源”(如 firebase.json 中的许多字段)使用glob 模式匹配表示法。这个规则不是重定向 index.html 上的所有内容(就像“**”一样),而是重定向不在图像文件夹和子文件夹中的所有内容。


Pad*_*ado 2

"hosting": {
  "rewrites": [
    {
      "source": "/images/**",
      "destination": "/something.html"
    },
    {
      "source": "**",
      "destination": "/index.html"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这将排除/images文件夹中的所有内容,将其重写为/something.html