Reputation: 941
Here is my use case, I made a simple example in order to ask this question, let's say I have two routes, /view1 and /view2, each mounting a component, View1 and View2, I need View1 to unmount when I go to /view2.
Here is the code if you want to try:
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, Link, browserHistory} from 'react-router';
import Portal from 'react-portal';
class View1 extends React.Component {
constructor(context, props) {
super(context, props)
}
componentDidMount() {
console.log('view 1 mounted');
}
componentWillUnmout() {
console.log('view 1 unmount');
}
render() {
return (
<h2>hanta</h2>
);
}
}
class View2 extends React.Component {
constructor(context, props) {
super(context, props)
}
componentDidMount() {
console.log('view 2 mounted');
}
componentWillUnmout() {
console.log('view 2 unmount');
}
render() {
return (
<h2>View 2</h2>
);
}
}
class View extends React.Component {
render() {
return (
<div>
<h1>View</h1>
<Link to="/view1">view 1</Link>
<Link to="/view2">view 2</Link>
{this.props.children}
</div>
);
}
}
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={View}>
<Route path="/view1" component={View1} />
<Route path="/view2" component={View2} />
</Route>
</Router>
, document.getElementById("container"))
ComponentWillUnmout doesn't get called in any case, I'm using:
Upvotes: 1
Views: 1159
Reputation: 2837
You spelled it wrong. It should be componentWillUnmount
, not componentWillUnmout
.
Upvotes: 1