【问题标题】:React Router Redux - Duplicate Renders when using Link or Back ButtonReact Router Redux - 使用链接或后退按钮时重复渲染
【发布时间】:2017-07-01 21:58:42
【问题描述】:

当我单击链接或使用后退按钮时,我看到重复的渲染。我可以转到任何页面并进行真正的浏览器刷新,一切都会正常工作。我的记录器显示@@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'));
}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-02-20
      • 2020-06-03
      • 2020-05-29
      • 2016-02-22
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      相关资源
      最近更新 更多