title: React Router v4 get current location
body: <p>I have just started using react-router V4 and I want to know how to get current location of router</p>
  
  <p>This is my source code</p>
  
  <pre><code>import {Meteor} from 'meteor/meteor';
  import React, {Component} from 'react';
  import ReactDOM from 'react-dom';
  import createHistory from 'history/createBrowserHistory'
  import {Route, BrowserRouter as Router, Switch} from 'react-router-dom'
  import {Tracker} from 'meteor/tracker';
  
  import Signup from '../imports/ui/signUp';
  import Link from '../imports/ui/link';
  import Login from '../imports/ui/login';
  import NotFound from '../imports/ui/notFound';
  
  const history = createHistory();
  const unauthenticatedPages = ['/', '/signup'];
  const authenticatedPages = ['/links'];
  
  const routes = (
      &lt;Router history={history}&gt;
          &lt;Switch&gt;
              &lt;Route exact path="/" component={Login}/&gt;
              &lt;Route exact path="/signup" component={Signup}/&gt;
              &lt;Route path="/links" component={Link}/&gt;
              &lt;Route component={NotFound}/&gt;
          &lt;/Switch&gt;
      &lt;/Router&gt;
  );
  Tracker.autorun(() =&gt; {
      const unlisten = history.listen((location, action) =&gt; {
          // location is an object like window.location
          console.log(action, location.pathname, location.state)
      })
  
      const isAuthenticated = !!Meteor.userId();
      console.log('location: ', location.pathname);
      //const pathName =
  });
  
  Meteor.startup(() =&gt; {
      ReactDOM.render(routes, document.getElementById('app'));
  }); 
  </code></pre>
  
  <p>I tried according to react-router documentation to use history but I didn't get the location.</p>
  
  <p>How to get current location of a route?</p>
  
  <p>I don't use redux and I will appreciate an answer without it.</p>
  
  <p>Thanks, Michael.</p>