title: React Router 4, How do I get a valid match url with route render or with withRouter?
body: <p>The match object I receive using either the render property on the Route component  or using an HOC from withRouter always produces a match object that is wrong. The location object is correct. The match url property is always '/'</p>
  
  <p>Here is a code pen that shows the problem <a href="https://codepen.io/stocksp/pen/jmoxoo?editors=1111" rel="nofollow noreferrer">React Router 4 match woes</a></p>
  
  <pre><code>const { render } = ReactDOM
  
      const {
        HashRouter,
        Route,
        Link
      } = ReactRouterDOM
  
      const App = () =&gt; (
        &lt;HashRouter&gt;
          &lt;div&gt;
            &lt;AddressBar/&gt;
  
            &lt;ul&gt;
              &lt;li&gt;&lt;Link to="/"&gt;Home&lt;/Link&gt;&lt;/li&gt;
              &lt;li&gt;&lt;Link to="/about"&gt;About&lt;/Link&gt;&lt;/li&gt;
              &lt;li&gt;&lt;Link to="/topics"&gt;Topics&lt;/Link&gt;&lt;/li&gt;
            &lt;/ul&gt;
  
            &lt;hr/&gt;
  
            &lt;Route exact path="/" component={Home}/&gt;
            &lt;Route path="/about" component={About}/&gt;
            &lt;Route path="/topics" component={Topics}/&gt;
          &lt;/div&gt;
        &lt;/HashRouter&gt;
      )
  
      const Home = () =&gt; (
        &lt;div&gt;
          &lt;h2&gt;Home&lt;/h2&gt;
        &lt;/div&gt;
      )
  
      const About = ({ match }) =&gt; (
        &lt;div&gt;
          &lt;h2&gt;About&lt;/h2&gt;
          &lt;h3&gt;Match: {match.url}&lt;/h3&gt;
        &lt;/div&gt;
      )
  
      const Topics = ({ match }) =&gt; (
        &lt;div&gt;
          &lt;h2&gt;Topics&lt;/h2&gt;
          &lt;ul&gt;
            &lt;li&gt;&lt;Link to={`${match.url}/rendering`}&gt;Rendering with React&lt;/Link&gt;&lt;/li&gt;
            &lt;li&gt;&lt;Link to={`${match.url}/components`}&gt;Components&lt;/Link&gt;&lt;/li&gt;
            &lt;li&gt;&lt;Link to={`${match.url}/props-v-state`}&gt;Props v. State&lt;/Link&gt;&lt;/li&gt;
          &lt;/ul&gt;
  
          &lt;Route path={`${match.url}/:topicId`} component={Topic}/&gt;
          &lt;Route exact path={match.url} render={() =&gt; (
            &lt;h3&gt;Please select a topic.&lt;/h3&gt;
          )}/&gt;
        &lt;/div&gt;
      )
  
      const Topic = ({ match }) =&gt; (
        &lt;div&gt;
          &lt;h3&gt;{match.params.topicId}&lt;/h3&gt;
          &lt;h3&gt;Match: {match.url}&lt;/h3&gt;
        &lt;/div&gt;
      )
  
      const AddressBar = () =&gt; (
        &lt;Route render={({ location: { pathname }, match: {url}, goBack, goForward }) =&gt; (
          &lt;div className="address-bar"&gt;
            &lt;div&gt;
              &lt;button
                className="ab-button"
                onClick={goBack}
              &gt;◀︎&lt;/button&gt;
            &lt;/div&gt;
            &lt;div&gt;
              &lt;button
                className="ab-button"
                onClick={goForward}
              &gt;▶&lt;/button&gt;
            &lt;/div&gt;
            &lt;div className="url"&gt;URL: {pathname} Match: {url}&lt;/div&gt;
          &lt;/div&gt;
  
        )}/&gt;
      )
  
      render(&lt;App/&gt;, document.getElementById('root'))
  </code></pre>
  
  <p>Click on the About link (Topics has the same issue): notice the AddressBar, which uses Route render, at the top always shows </p>
  
  <pre><code>&gt; Match: /
  </code></pre>
  
  <p>while at the bottom of the screen the Component displays the correct match.url</p>
  
  <p><code>Match: /about</code></p>
  
  <p>What am I doing wrong? How do I get a valid match object into the AddressBar?</p>
  
  <p>Here is the ugly hack I used for my specific route where I need to know the specific 'league' parameter.</p>
  
  <pre><code>let keys = []
  let path = '/*/:league/:id';
  if (this.path.split('/').length === 3)
    path = '/*/:league';
  let re = pathToRegexp(path, keys);
  const result = re.exec(this.path)
  if (result &amp;&amp; result[2])
    this.store.setLeague(result[2]);
  </code></pre>