react router包含两个参数browserHistory hashHistory,官方文档推荐browserHistory
<Router history={browserHistory}>
browserHistory使用的是HTML5的History API,浏览器提供相应的接口修改浏览器的历史记录。hashHistory是通过改变地址后面的hash来改变浏览器的历史记录。
History API提供了pushState和replaceState增加替换历史记录,但是hash没有替换历史记录功能
此外hash 部分并不会被浏览器发送到服务端,也就是说不管是请求 www.index.html#foo 还是 www.index.html#bar ,服务只知道请求了 index.html 并不知道 hash 部分的细节。而 History API 需要服务端支持,这样服务端能获取请求细节。
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Hello} />
{routeMap.map((route, i) => <Route key={i} path={route.path} component={route.component} />)}
</Route>
<Route path="*" component={NotFound404} />
</Router>