react router v^4.0.0 Uncaught TypeError: Cannot read property 'location' of undefined

前端 未结 4 1595
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 15:57

I\'ve been having some trouble with react router (i\'m using version^4.0.0).

this is my index.js

import React from \'react\';
import ReactDOM from \'         


        
4条回答
  •  生来不讨喜
    2020-12-12 16:17

    You're doing a few things wrong.

    1. First, browserHistory isn't a thing in V4, so you can remove that.

    2. Second, you're importing everything from react-router, it should be react-router-dom.

    3. Third, react-router-dom doesn't export a Router, instead, it exports a BrowserRouter so you need to import { BrowserRouter as Router } from 'react-router-dom.

    Looks like you just took your V3 app and expected it to work with v4, which isn't a great idea.

提交回复
热议问题