我正在使用React Router 4。
当我使用render参数渲染组件时,componentWillReceiveProps()第一次不会触发,因此我需要点击两次才能将props发送到组件。
我这样渲染:
const CartRoute = (props) => (<Cart itemsInCart = {this.state.itemsInCart} deleteItemFromCart = {this.deleteItemFromCart} {...props} />);
.....
<Switch>
.....
<Route path="/cart" render={CartRoute} />
</Switch>
没有路由器(当所有组件都在同一页时)它可以正常工作。
以下是详细描述: