当我按下按钮时我想重定向,所以我用它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) 我想在没有引导程序的情况下实现滚动间谍。
我在网上查了很多代码,都是用jQuery实现的。
如何仅使用 React 的强大功能来实现scrollspy?
我想通过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)