React Router 4 and props.history.push

后端 未结 2 723

There\'s something driving me crazy in React, and I need your help. Basically, when the user clicks \"My Profile\", I want to redirect to the user\'s profile. To do that, I use

2条回答
  •  长情又很酷
    2021-01-23 05:12

    You need to integrate the react-router-redux.

    Its look like the updated state is not reflecting in the container as redux do shallow comparison to check whether the component need to be update or not.

    import {Router} from 'react-router-dom';
    import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux';
    import createHistory from 'history/createBrowserHistory';
    
    const history = createHistory()
    const middleware = routerMiddleware(history)
    
    
    const rootReducer = combineReducers({
        router: routerReducer,
      //other reducers
    });
    
    const store = createStore(rootReducer,applyMiddleware(middleware));
    
    
    
     //routes
    
    
    

    Also,at reducers,add this snippet.

    let updatedStore = JSON.parse(JSON.stringify(state));
    

提交回复
热议问题