【问题标题】:React-router doesn't handle hash from my pathReact-router 不处理我路径中的哈希
【发布时间】:2017-08-13 22:35:26
【问题描述】:

我的 react-router 设置如下:

<Router history={browserHistory}>
     <Route path="/" component={App}>
     {/* other routes */}
</Router>

我正在使用来自 react-router 的browserHistory

我的应用程序在 Amazon S3 存储桶上,当我发出初始请求时,在 Chrome 和 Firefox 上一切正常,但在 Safari、Edge 和 IE 上却无法正常工作。

我看到在服务器上添加的路径中添加了哈希。

所以基本上如果我输入:

https://example/foo

变成:

https://example/#/foo

我的 react-router 不知道如何正确路由它,因为我的路由中没有定义带有哈希的路由。难道我做错了什么?提前致谢。

【问题讨论】:

    标签: javascript reactjs amazon-s3 react-router


    【解决方案1】:

    考虑使用hashHistory 而不是browserHistory,这在React 路由器中也可以通过import { hashHistory } from 'react-router' 使用。 (eg. &lt;Router history={hashHistory}&gt; 而不是&lt;Router history={browserHistory}&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-05
      • 2018-04-18
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      相关资源
      最近更新 更多