结合React Router和Firebase功能api

时间:2019-10-21 01:10:29

标签: reactjs firebase google-cloud-functions react-router-dom

我想知道是否可以同时使用react-router-dom和firebase函数。例如,React部分具有一些链接,例如mywebsite.com/pageone、mywebsite.com/pagetwo、mywebsite.com/pagethree。我想添加一个来自firebase函数的mywebsite.com/api链接。我查阅了Firebase文档,但只显示了两者之一。这可能吗?这是firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      },
      {
        "source": "/app/api",
        "function": "app"
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:2)

尝试更改重写顺序,以使通配符在末尾。那为我解决了。

发件人:

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

收件人:

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