只有在尝试通过地址栏访问路由时,才会对firebase上托管的路由器应用程序发出404错误

时间:2018-04-23 05:58:56

标签: reactjs firebase react-router

我有一条路线https://playlists-22855.firebaseapp.com/client/create,当您尝试通过点击“主题”链接进行访问时,我可以做得很好。但是当我尝试通过地址栏直接访问该路由时,我收到404错误。我想知道如何纠正我的代码,可以找到here on codesandbox。另一个有趣的事情是代码在codeandbox上运行得很好,但是它有一个创建反应应用程序应用程序,而我的不是。谢谢。

1 个答案:

答案 0 :(得分:1)

我也遇到了这个问题-通过将我的应用程序配置为单页应用程序来解决。最初使用firebase init时,您可以选择此选项。现在,您可以通过手动更改firebase.json文件来做到这一点。

您要将其添加到firebase.json

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

所以您的firebase.json看起来像这样

{
  "hosting": {
    "target": "your-app-name",
    "public": "your-build-directory",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
相关问题