Firebase在子文件夹中的单页VueJS应用程序中重写

tay*_*mer 3 javascript firebase vue.js firebase-hosting

背景

我有一个结构如下的网站:

root
  — /public
    — index.html <— landing page
    — 404.html
    — /library 
      — index.html <— single page VueJS app
Run Code Online (Sandbox Code Playgroud)

单页应用程序可在此处找到:https://uxtools-3ac6e.firebaseapp.com/library/

这是我的firebase.json:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/library/*",
        "destination": "/library/index.html"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

问题

当应用程序开始路由到子路径时,例如https://uxtools-3ac6e.firebaseapp.com/library/lists/order-group-best-sources-learn-ux,刷新将重定向到404而不是库/索引html的.

Mic*_*igh 8

你需要使用双星形的glob来匹配:

"source": "/library/**"
Run Code Online (Sandbox Code Playgroud)

单星只会匹配斜线,所以匹配/library/lists但不匹配/library/lists/foo.