编程语言
首页 > 编程语言> > javascript – React Router Redux – 使用链接或后退按钮时重复渲染

javascript – 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'));
}

解决方法:

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

标签:javascript,react-router,react-redux,react-router-redux
来源: https://codeday.me/bug/20190706/1392337.html