一、history.push()無法跳轉
參考了很多文章 研究一下生命周期 render是要有state變化才會執行 BrowserHistory只有props變化 無法觸發render
如下改造
環境
"react": "^17.0.2", "react-cookies": "^0.1.1", "react-dev-utils": "^11.0.4", "react-dom": "^17.0.2", "react-router": "^5.2.0", "react-router-dom": "^5.2.0",
這樣在你需要跳轉的function里寫
this.props.history.push('/')
即可 不需要工廠方法creatBrowserHistory去創建history