【发布时间】:2020-07-01 02:24:42
【问题描述】:
我正在尝试使用“react”在反应路由器之间添加动画:“^16.13.1”、“react-router-dom”:“^5.2.0”、“react-transition-group”:“^4.4 .1"。但是出现错误提示“TypeError: Cannot read property 'location' of undefined”,如何解决?
MainComponent.js
...
return (
<div>
<Header />
<TransitionGroup>
<CSSTransition key={this.pops.location.key} classNames="page" timeout={300}>
<Switch>
<Route path='/home' >{HomePage}</Route>
<Route exact path='/contactus' component={() => <Contact resetFeedbackForm={this.props.resetFeedbackForm}/>} />
<Route exact path='/menu' component={() => <Menu dishes={this.props.dishes} />} />
<Route path='/menu/:dishId' component={DishWithId} />
<Route exact path='/aboutus' component={() => <About leaders={this.props.leaders} />} />
<Redirect to="/home" />
</Switch>
</CSSTransition>
</TransitionGroup>
<Footer />
</div>
);
}
...
如何获取位置密钥?
【问题讨论】:
-
pops应该是props... -
@BrianThompson 对,你有一个错字。另外,
CSSTransition不需要key道具。您可以删除该道具。 -
@BrianThompson 我已将
pops更正为prop。仍然出现同样的错误。 -
@PasVV 我从
CSSTranstion中删除了key,错误已解决,但路由之间没有动画。 -
澄清一下,你确定你仔细看了the docs?
标签: javascript reactjs react-router-dom react-transition-group