React router not showing browser history

后端 未结 5 2062
一个人的身影
一个人的身影 2021-01-01 16:38

I\'m learning from this tutorial but I keep getting this error:

\'react-router\' does not contain an export named \'browserHistory\'.

相关标签:
5条回答
  • 2021-01-01 17:09

    I have solved the problem. just install the latest react-router component. for more you can go through the following article. https://www.developers-zone.com/best-react-router-example-in-react-application/

    0 讨论(0)
  • 2021-01-01 17:13

    You need to get browserHistory from the history module now.

    import createHistory from 'history/createBrowserHistory'
    

    Note that they changed the module API recently so if you are using the latest version the import slightly changed:

    import { createBrowserHistory } from 'history'
    
    0 讨论(0)
  • 2021-01-01 17:15

    You are using version 4 of react-router.

    Either downgrade the package or follow the instructions in this SO answer to make it work with v4.

    0 讨论(0)
  • 2021-01-01 17:33

    I had the same problem and I wasted a couple of days to figure it out. This error happens simply because react-router v4 does not have the browserHistory (I don't know if that's a good thing or not though). I solved the issue by installing v3 like this:

    npm install react-router@3 --save
    
    0 讨论(0)
  • 2021-01-01 17:35

    Simple Solution

    method 1:

    npm install --save history
    
    use this now:
    
    import createHistory from 'history/createBrowserHistory'
    

    method:2

    Use Version 3  
    
    npm install react-router@3
    
    0 讨论(0)
提交回复
热议问题