JSFiddle - React, Tailwind, and code Playground
by sfoster
HTML
<script type="text/javascript" src="https://raw.github.com/mtrpcic/pathjs/master/path.js"></script>
<!-- fixed in https://raw.github.com/sfoster/pathjs/false-path-matches/path.js -->
<ul id="outcomes">
<li class="smokeTest">smoke/test</li>
<li class="pathDupes">path/path/dupes</li>
<li class="rescue">rescue</li>
</ul>
<a href="#smoke/test">smoke test</a> |
<a href="#path/path/dupes">path dupes</a>
<hr/>
<h1>Explanation</h1>
<p>The parameterized path matching code uses substring matching and so trips up if the path has another occurence of the same string before the place where it should be inserted. So, given #path/:id/dupes, it finds the first 'path' in #path/path/dupes so all the indexes are wrong</p>
CSS
.active { background-color: yellow; font-weight: bold; }
JavaScript
console.log("Path: ", Path);
// test the Path library is working at all
Path.map("#smoke/test").to(function(){
console.log("matched #smoke/test path");
$('#outcomes li').removeClass('active');
$('#outcomes li.smokeTest').addClass('active');
});
// test of the duplicate token problem
Path.map("#path/:id/dupes").to(function(){
$('#outcomes li').removeClass('active');
$('#outcomes li.pathDupes').addClass('active');
});
Path.rescue(function(){
$('#outcomes li').removeClass('active');
$('#outcomes li.rescue').addClass('active');
});
Path.listen();