我正在使用react-router进行路由,我使用hashHistory选项,以便我可以从浏览器刷新页面或指定我现有路线的URL并登陆到右侧页面.
它工作正常,但我在网址中看到这样的哈希:
http://localhost/#/login?_k=ya6z6i
它工作正常,但我在网址中看到这样的哈希:
http://localhost/#/login?_k=ya6z6i
这是我的路由配置:
ReactDOM.render(( <Router history={hashHistory}> <Route path='/' component={MasterPage}> <IndexRoute component={LoginPage} /> <Route path='/search' component={SearchPage} /> <Route path='/login' component={LoginPage} /> <Route path='/payment' component={PaymentPage} /> </Route> </Router>),document.getElementById('app-container'));
您是否尝试过browserHistory选项?您还可以从浏览器刷新页面或指定其中一条现有路线的URL并登陆右侧页面.
import { Router,Route,browserHistory } from 'react-router'; ReactDOM.render(( <Router history={browserHistory}> <Route path='/' component={MasterPage}> <IndexRoute component={LoginPage} /> <Route path='/search' component={SearchPage} /> <Route path='/login' component={LoginPage} /> <Route path='/payment' component={PaymentPage} /> </Route> </Router>),document.getElementById('app-container'));
而且考虑到react-router github doc,hashHistory不能用于生产.
https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md#browserhistory
我应该使用hashHistory吗?
Hash history works without configuring your server,so if you’re just getting started,go ahead and use it. But,we don’t recommend using it in production,every web app should aspire to use browserHistory
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。