React history.push() not rendering new component

前端 未结 5 1131
梦谈多话
梦谈多话 2021-01-02 09:31

I have a React.js project with a simple sign in function. After the user is authorized, I call history.push method which changes the link in the address bar but does not ren

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 09:40

    First, create a history object used the history package:

    // src/history.js
    import { createBrowserHistory } from 'history';
    export default createBrowserHistory();
    

    Then wrap it in in Main Router Component.

        import { Router, Route, Link } from 'react-router-dom';
        import history from './history';
    
        ReactDOM.render(
            
              
                
                  
    )

    Here, After dispatching the request, redirecting to home page.

        function requestItemProcess(value) {
            return (dispatch) => {
                dispatch(request(value));
                history.push('/');
            };
    
        }   
    

    should be helpful :)

提交回复
热议问题