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 renders 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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -