简体   繁体   English

React Router 1.0-历史问题

[英]React router 1.0 - Issue with history

I'm using react-router 1.0 rc, and I'm having a bit of an issue with the history. 我正在使用react-router 1.0 rc,并且历史记录有点问题。 I'm using createBrowserHistory() , when I do route transitions, I'm using pushState and replaceState which is working in the address bar, but not reloading the page, and hard refreshes on any page appends the #/?_k=789x0c to the url, which makes me think the app isn't using history correctly. 我正在使用createBrowserHistory() ,当我进行路由转换时,我正在使用在地址栏中工作的pushStatereplaceState ,但没有重新加载页面,并且任何页面上的硬刷新都将#/?_ k = 789x0c附加到网址,这让我觉得该应用未正确使用历史记录。

I've got a bit too much code to post, but the below should be enough to see how I'm using history (same as most examples really). 我要发布的代码太多了,但是下面的内容应该足以了解我如何使用历史记录(实际上与大多数示例相同)。

history.js: history.js:

import createBrowserHistory from 'history/lib/createBrowserHistory';

export default createBrowserHistory();

index.js: index.js:

import history from './history';

React.render(
  <Provider store={store} history={history}>
    {() => <Router>{routes}</Router> }
  </Provider>,
  document.querySelector('#app')
);

对于任何具有类似情况的人,此问题是由于将历史记录道具放置在<Provider>组件而不是<Router> ,这是一个愚蠢的错误,这是迁移到1.0的副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM