小编leu*_*ion的帖子

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 实现滚动间谍

我想在没有引导程序的情况下实现滚动间谍

我在网上查了很多代码,都是用jQuery实现的。

如何仅使用 React 的强大功能来实现scrollspy

javascript scrollspy reactjs

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

如何将redux-form与reselect一起使用

我想通过redux-form使用reselect从redux获取值。问题是我不知道如何将getFormValues与重新选择结合起来。看来我无法在createSelector中访问状态。因此我无法提出在重新选择中使用redux-form的选择器的方法。

例如:

// How to access the state here?
const getFoo = createSelector(
  [getBar],
  (bar) => {
    // return something
  }
)
Run Code Online (Sandbox Code Playgroud)

redux中的选择器的工作原理如下:

getFormValues('formName')(state);
Run Code Online (Sandbox Code Playgroud)

reactjs redux redux-form reselect

5
推荐指数
1
解决办法
1372
查看次数