React Router Redux - 使用链接或后退按钮时重复渲染

时间:2017-02-13 19:35:45

标签: javascript react-router react-redux react-router-redux

当我点击链接或使用后退按钮时,我看到了重复的渲染。我可以去任何页面并进行真正的浏览器刷新,一切都会正常工作。我的记录器显示两次@@ router / LOCATION_CHANGE,这导致了大量事件重复实例的警告和异常。这似乎不是hashHistory与browserHistory的问题。正如人们已经指出github问题。我正在" react-router-redux":" 4.0.7"。将adjustUrlOnReplay设置为false并不会显示任何操作。一如既往,非常感谢任何帮助!下面是我的configureStore和Routes js文件。任何人都可以帮我找到问题吗?谢谢!菲利普

configureStore.js

import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import thunk from 'redux-thunk'
import logger from 'redux-logger'
import rootReducer from '../reducers'
import createSagaMiddleware from 'redux-saga'
import rootSaga from '../sagas/sagas'
import promiseMiddleware from 'redux-promise-middleware'
import { syncHistoryWithStore} from 'react-router-redux'
import { browserHistory } from 'react-router'
import { apiMiddleware } from 'redux-api-middleware';

const sagaMiddleware = createSagaMiddleware()

const initialState = {
};

const enhancers = compose(
  window.devToolsExtension ? window.devToolsExtension() : f => f
);

const store = createStore(rootReducer, initialState, compose(
    applyMiddleware(apiMiddleware, thunk, logger(), sagaMiddleware),
    typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
  ));

export const history = syncHistoryWithStore(browserHistory, store);
sagaMiddleware.run(rootSaga);
export default store;

routes.js

import App from './App'
import '...a bunch of different components'
import { Provider } from 'react-redux'
import { Router, Route, IndexRoute, browserHistory } from 'react-router'
import store, { history } from './store/configureStore.js'

const router = (
  <Provider store={store}>
    <Router history={history}>
      <Route path="/" component={App}>
        <IndexRoute component={TeamsContainer}/>
        <Route path="teams" component={TeamsContainer} />
        <Route path="teams/:teamId" component={TeamContainer} />
        <Route path="teams/:teamId/add_member" component={AddMemberContainer} />
        <Route path="teams/:teamId/team_members/:teamMemberId" component={TeamMemberContainer} />
      </Route>
    </Router>
  </Provider>
)

if ( $('#app').length ) {
  ReactDOM.render(router, document.getElementById('app'));
}

1 个答案:

答案 0 :(得分:1)

https://github.com/ReactTraining/history/issues/427 更新到react-router v4解决了这个问题。