react-router v4 - browserHistory is undefined

前端 未结 5 484
南笙
南笙 2020-12-05 14:34

I am creating my first react app in electron (my first electron app too). I have two routes & need to navigate from one to another. For that I am using following code:

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 15:04

    In react-router v4 initialize router as constant config and access the history through this.props in child components.

    Import you dependecies

    import { Route, Router } from "react-router";
    import { createBrowserHistory } from "history";
    

    Define your router config and add history as prop

    const history = createBrowserHistory();
    const routes = (
      
        
        
       )
    
    class App extends Component {
      render() {
        return ( 
        
提交回复
热议问题