ExpressJS and EJS are my chosen technologies for creating Views.
When it comes to the navigation bar, I want to add a class="active"
to the links that represent the current page. However, if I use partials in my views, how can I achieve this?
Here is a quick example:
Index.ejs
<ul class="nav navbar-nav navbar-right">
<li><a class="active" href="/Index">Home</a></li>
<li><a href="/About">About</a></li>
<li><a href="/Work">Work</a></li>
</ul>
About.ejs
<ul class="nav navbar-nav navbar-right">
<li><a href="/Index">Home</a></li>
<li><a class="active" href="/About">About</a></li>
<li><a href="/Work">Work</a></li>
</ul>
Work.ejs
<ul class="nav navbar-nav navbar-right">
<li><a href="/Index">Home</a></li>
<li><a href="/About">About</a></li>
<li><a class="active" href="/Work">Work</a></li>
</ul>
This is my current method of handling active links in the navbar by including it on each page individually
Is there a more efficient approach where I don't have to render the navbar every time I create a new page?