Reputation: 172
I am not seeing react-router unmount component when the route is a sub-route
So even if I switch between path/1 and path/2, componentWillUnmount never gets called for the instance of ComponentForRoute. Any suggestions? Is this how react-router is suppose to work? If so, any suggestions on handling route changes?
Tried using componentWillReceiveProps, but i guess its deprecated now?
<Router history={history}>
<Route path="path/:paramId" component={ComponentForRoute} />
</Router>
Upvotes: 2
Views: 403
Reputation: 809
componentDidUpdate (prevProps) {
if (this.props.location !== prevProps.location) {
//YOUR CODE HERE
}
}
Also, component has to be wrapped with withRouter
.
Upvotes: 1