Настроить перенаправления на Firebase Hosting SPA + 2 подпапки firebase.json - PullRequest
0 голосов
/ 12 сентября 2018

У меня есть общая папка, например:

/public
   index.html

   /landing
     index.html

   /membership
     index.html

/ public / index.html - это SPA, поэтому каждый запрос к / ** должен переписываться в /index.html

/ Landing / и / members / - это две статические привязки HTML, поэтому каждый запрос не следует переписывать

firebase.json, предложенный службой поддержки Google:

{
    "functions": {
        "source": "functions"
    },
    "hosting": {
        "public": "public",
        "redirects": [{
                "source": "/landing",
                "destination": "index.html"
            },
            {
                "source": "/membership",
                "destination": "index.html"
            }
        ],
        "rewrites": [{
                "source": "/membership/**",
                "destination": "/membership/index.html"
            }
        ],
        "ignore": [
            "firebase.json",
            "**/.*",
            "**/node_modules/**"
        ]
    }
}

Все просто перенаправляется в / index.html ...

Даже пробовал с:

{
  "functions": {
      "source": "functions"
  },
  "hosting": {
      "public": "public",
      "redirects": [{
              "source": "/landing/**",
              "destination": "/landing/index.html"
          },
          {
              "source": "/membership/**",
              "destination": "/membership/index.html"
          }
      ],
      "rewrites": [{
              "source": "**",
              "destination": "/index.html"
          }
      ],
      "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
      ]
  }
}

Тот же результат, все просто идет к /

1 Ответ

0 голосов
/ 14 сентября 2018

Вам не нужно использовать «перенаправления».Juste использует эти правила переписывания:

{
    "functions": {
        "source": "functions"
    },
    "hosting": {
        "public": "public",
        "ignore": [
            "firebase.json",
            "**/.*",
            "**/node_modules/**"
        ],
        "rewrites": [
            {
                "source": "!/@(landing|membership)/**",
                "destination": "/index.html"
            },
            {
                "source": "/landing/**",
                "destination": "/landing/index.html"
            },
            {
                "source": "/membership/**",
                "destination": "/membership/index.html"
            }
        ]
    }
}

Первое правило переписывает все, кроме того, что начинается с приземления ИЛИ членства.Второе правило позаботится о посадочных дорожках.И третий будет указывать, что делать со всеми путями членства.

...