[react-router] hashHistory 和 browserHistory 的区别
react-router提供了三种方式来实现路由,并没有默认的路由,需要在声明路由的时候,显式指定所使用的路由。 //v1.x
<Router/>
//v2.0.0 // hash history import { hashHistory } from ‘react-router‘ <Router history={hashHistory} />
官方推荐使用browserHistory 使用hashHistory,浏览器的url是这样的:/#/user/liuna?_k=adseis 使用browserHistory,浏览器的url是这样的:/user/liuna 这样看起来当然是browerHistory更好一些,但是它需要server端支持。 使用hashHistory时,因为有 # 的存在,浏览器不会发送request,react-router 自己根据 url 去 render 相应的模块。 使用browserHistory时,从 / 到 /user/liuna,浏览器会向server发送request,所以server要做特殊请求,比如用的 express 的话,你需要 handle 所有的路由? ? 如果只是静态页面,就不需要用browserHistory,直接hashHistory就好了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |