title: React: history.listen - How to unlisten?
body: <p>On one module, I need to listen to the url change, so I wrote a simple code:</p>
  <pre><code>componentDidMount(){
          history.listen( location =&gt;  {
              console.log('listen')
              doSomeStuff(location);
          });
      }
  </code></pre>
  <p>But after leaving the page where this module is used, I still see <code>console.log('listen)</code>, it turns out that the listener still performs a function <code>doSomeStuff(location)</code>, even where it is not necessary?</p>
  <p>I read the documentation that says, quote:</p>
  <blockquote>
  <p>&quot;When you attach a listener using history.listen, it returns a function that can be used to remove the listener, which can then be invoked in cleanup logic:&quot;</p>
  <pre><code>const unlisten = history.listen(myListener);
  // ...
  unlisten();
  </code></pre>
  </blockquote>
  <p>I do not understand what I need to write in <code>ComponentWillUnmount</code> to stop this listener.</p>
  <p>I am using <code>2.8.0</code> version of <code>react-router</code></p>