我正在使用从https://github.com/facebookincubator/create-react-app创建的 ReactJS SPA
我正在使用 S3 和 Cloudfront 为我的网站提供服务。一切正常,直到我重新加载页面 - 它抛出一个错误(在我的情况下访问被拒绝),因为它无法在没有 Hashbang 的情况下处理。
注意:如果我输入带有 hashbang 的 URL,它可以正常工作
所以本质上,这有效:https://example.com/#/dashboard(重定向到https://example.com/dashboard)
但是如果我刷新页面,它会给出如下错误:
我们使用 browserHistory 来维护路由。我只显示相关代码:
<Router history={browserHistory}>
<Route path='/dashboard' component={Dashboardpage} />
</Router>