TypeError: Cannot read property ‘location‘ of undefined 报错解决办法

react-router-dom 默认版本问题,

 

改用hashrouter解决

 

import { HashRouter, Route, Switch, Redirect, Link } from 'react-router-dom'
<HashRouter>
      <Switch>
          <Route path="app" component={App} />
          <Route path="about" component={About} />
          <Route path="inbox" component={Inbox}>
            <Route path="messages/:id" component={Message} />
          </Route>
        <Redirect from="/" to="/app" exact />
      </Switch>
    </HashRouter>

 

posted @ 2021-10-07 12:43  Redchar  阅读(812)  评论(0编辑  收藏  举报