【问题标题】:history.push not working when using BrowserRouter使用 BrowserRouter 时 history.push 不起作用
【发布时间】:2017-02-23 20:00:15
【问题描述】:
//startup file
import {BrowserRouter} from 'react-router';
 let root=(<BrowserRouter>
            //Some components
         </BrowserRouter>);                                                                  
 ReactDOM.render(Root, document.getElementById("app"));    

// function to navigate or route
import createBrowserHistory from 'history lib createBrowserHistor';
const history = createBrowserHistory();

let browseTo=function(path){
     history.push({pathname: path})
})

调用上述函数后,只执行 URL 路径更改实际路由。

Like URL localhost:8080 更改为 localhost:8080/login 不路由到登录组件。

【问题讨论】:

    标签: reactjs react-router browser-history


    【解决方案1】:

    https://github.com/ReactTraining/react-router/issues/4059

    browserHistory 在 v4 中没有被 react-router 公开,仅在 v2 中。

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 1970-01-01
      • 2019-09-21
      • 2020-12-15
      • 1970-01-01
      • 2019-11-04
      • 2022-11-04
      • 2021-03-11
      • 2020-01-23
      相关资源
      最近更新 更多