加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 如何从react-router中的url中删除哈希值

发布时间:2020-12-15 20:53:52 所属栏目:百科 来源:网络整理
导读:我正在使用react-router进行路由,我使用hashHistory选项,以便我可以从浏览器刷新页面或指定我现有路线的URL并登陆到右侧页面. 它工作正常,但我在网址中看到这样的哈希: http://localhost/#/login?_k=ya6z6i 这是我的路由配置: ReactDOM.render(( Router hi
我正在使用react-router进行路由,我使用hashHistory选项,以便我可以从浏览器刷新页面或指定我现有路线的URL并登陆到右侧页面.
它工作正常,但我在网址中看到这样的哈希:
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读