【发布时间】:2017-10-06 22:36:31
【问题描述】:
我正在使用 React Router 4。
当我使用渲染参数 componentWillReceiveProps() 渲染组件时,它不会第一次触发,所以我需要单击两次才能将道具发送到组件。
我是这样渲染的:
const CartRoute = (props) => (<Cart itemsInCart = {this.state.itemsInCart} deleteItemFromCart = {this.deleteItemFromCart} {...props} />);
.....
<Switch>
.....
<Route path="/cart" render={CartRoute} />
</Switch>
没有路由器(当所有组件都在同一页面上时)它工作正常。
这里有详细说明:
React router - Need to click LINK twice to pass props to Component
【问题讨论】:
标签: reactjs components react-router render router