javascript - React-router: Refreshing the child page contents with hashHistory.push -
i'm working on spa uses react router so:
<router> <route path="/" component={base}> <indexroute component={home}/> <route path="features/:id" component={single} /> </route> </router>
i have component attached base supposed update contents of single via:
hashhistory.push(`features/${val.value}`);
the page url updates once in child route, change hashhistory doesn't cause child state update. ideas how can reload content here?
you need add componentwillreceiveprops
lifecycle method. respond prop changes render
s except initial one. recall coming router prop.
// example: feature id changed in url componentwillreceiveprops(nextprops) { if (this.props.params.id !== nextprops.params.id) { this.setstate(...); } }
Comments
Post a Comment