有没有办法省略react-router中的前导斜杠?

时间:2016-12-04 18:02:24

标签: javascript reactjs react-router

我尝试将应用程序从自定义库迁移到react / redux。我正在调查使用react-router作为我们的顶级路由工具。

我计划使用hashHistory,因为我们现有的路径树完全是在哈希中完成的。但是,我们现有的路径树在#之后不包含前导斜杠。

为了不破坏我们现有的所有链接,我想知道是否有办法省略前导斜杠。

到目前为止,我一直在尝试:

import {createHashHistory} from 'history'

const custom_history = useRouterHistory(createHashHistory)({
  hashType: 'noslash'
})

class Router extends Component {
  render() {
    return (
      <Router history={custom_history}>
        <Route path="" component={Container}>
           <Route path="dashboard" component={SubContainer} />
        </Route>
      </Router>
    )
  }
}

但直接在createHashHistory库中使用history似乎会在getCurrentLocation的第二次嵌套history.listen调用中导致错误。

有没有办法在react-router ^ 3.0.0中执行此操作?

0 个答案:

没有答案