关于react-router的hashhistory

用react-router 的时候报这个warn:

bundle.js:22167 Warning: [react-router] Router no longer defaults the history prop to hash history. Please use the hashHistory singleton instead.

是不是说不支持直接写入hash格式的历史到浏览器历史中了?(感觉不是..
自己对这个错误理解的好像不是很对,想请有经验人士在帮助解释一下。

还有自己看Github上的示例有用到:

import useBasename from 'history/lib/useBasename'

// This helper is for setting basename on examples with minimal boilerplate. In
// an actual application, you would build a custom history to set basename.
export default function withExampleBasename(history, dirname) {
  return useBasename(() => history)({ basename: `/${dirname}` })
}

之后

render((
  <Router history={withExampleBasename(browserHistory, __dirname)}>
    <Route path="/" component={App}>
      <IndexRoute component={Index}/>
      <Route path="/about" component={About}/>
      <Route path="/users" component={Users}>
        <IndexRoute component={UsersIndex}/>
        <Route path=":id" component={User}/>
      </Route>
    </Route>
  </Router>
), document.getElementById('example'))

以前用history这个包的时候也没有这样用过,想请经验人士帮助解释一下,感激不尽!

阅读 7.7k
1 个回答
  <Router history={withExampleBasename(browserHistory, __dirname)}>

改成

<Router hashHistory={withExampleBasename(browserHistory, __dirname)}>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题