相关疑难解决方法(0)

React-Router v4:无法读取未定义的属性"route"

当我按下按钮时我想重定向,所以我用它withRouter来获取历史道具的访问权限.

但我得到错误:

Uncaught TypeError: Cannot read property 'route' of undefined
  at Route.computeMatch (react-router.js:1160)
Run Code Online (Sandbox Code Playgroud)

使用withRouterHOC 包装组件时出错.如果我删除withRouter功能,它只是工作.

我的代码如下所示:

class App extends Component {

// ...some unrelated functions

handleTitleTouchTap = e => {
    e.preventDefault()
    const { history } = this.props
    history.push('/')
}

render() {
                //...other components
        <Router>
            <div>      
                <Switch>
                    <Route exact={true} path="/" component={Home} />
                    <Route path="/search" component={Search}/>
                    <Route path="/gamelist/:listId" component={GameListDetail}/>
                    <Route path="/game/:gameId" component={GameDetail}/>
                    <Route path="/manageuser" component={ManageUser} />
                    <Route path="/addgamelist" component={AddGameList} />
                    <Route path="/addgame" component={AddGame} />
                    <Route path="/test" …
Run Code Online (Sandbox Code Playgroud)

react-router

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

react-router ×1