首页 > 解决方案 > reactJs项目如何直接访问路由

问题描述

我正在开发一个 reactJS 应用程序,我需要让用户能够直接访问它的路由。但是我什么时候得到404。

<Router>
<>
  <Route exact path="/" component={App} />
  <Route path="/video" component={YoutubeVideoScreen} />
</>
</Router>

当我尝试访问“www.hostname.com/video”时,它给了我一个 404 错误。我认为问题在于与单页应用程序相关的 apache 配置。以前,我在将类似的应用程序上传到 firebase 托管时遇到了同样的问题,但我通过在 firebase.json 中添加类似下面的内容解决了这个问题。

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

那么,如何在 apache 服务器中实现这一点呢?

标签: reactjsapachesingle-page-application

解决方案


推荐阅读