title: How to check if route matches a pattern with React-Router v4?
body: <p>How can I check if a route pattern matches the current route using React Router v4 without the <code>Route</code> or <code>NavLink</code> components or writing my own regex to match against the route?</p>
  
  <p>For example, if the route is <code>/users/5/friends/3/pets/10/edit</code>, I want to be able to check if the route matches a pattern (like the one used by <code>Route</code> and <code>NavLink</code>). Something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>const isEditFriendPetRoute = routeMatches('/users/:userId/friends/:friendId/pets/:petId/edit');
  
  console.log(
    isEditFriendPetRoute 
      ? `Is editing friend's pet`
      : `Is not editing friends pet`
  )
  </code></pre>