JSFiddle - React, Tailwind, and code Playground
HTML
<!-- exemplo retirado de http://www.itworld.com/article/2832973/development/setting-an-active-menu-item-based-on-the-current-url-with-jquery.html -->
<header>
<ul class="nav">
<li><a href="pagina.html">Home</a>
</li>
<li>|</li>
<li><a href="pagina2.html">Pagina</a>
</li>
<li>|</li>
<li><a href="pagina3.html">Sobre</a>
</li>
<li>|</li>
<li><a href="pagina4.html">Contato</a>
</li>
</ul>
</header>
CSS
a {
color:#000;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
a:visited {
color:#000;
}
.nav {
padding:10px;
border:solid 1px #c0c0c0;
border-radius:5px;
float:left;
}
.nav li {
list-style-type:none;
float:left;
margin:0 10px;
}
.nav li a {
text-align:center;
width:55px;
float:left;
}
.nav li.active {
background-color:green;
}
.nav li.active a {
color:#fff;
font-weight:bold;
}
JavaScript
/**
O autor deste codigo Ă© Matthew Mombrea
*/
$(function () {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
$(".nav a").each(function () {
var href = $(this).attr('href');
if (path.substring(0, href.length) === href) {
$(this).closest('li').addClass('active');
}
});
});