Right now, I am doing this via jQuery, like so:
$(".navigation__item a").each(function () {
if (window.location.pathname === $(this).attr("href")) {
$(this).parent().addClass("active");
}
});
However, this isn't full-proof so I'd like to pass along an "active" parameter to my navigation view, but I'm unsure of how to do that. Here's a snippet of my navigation template:
<aside class="navigation-wrap">
<ul class="navigation">
<li class="navigation__item{{#if current}} active{{/if}}">
<a href="/admin/dashboard">Overview</a>
</li>
<li class="navigation__item{{#if current}} active{{/if}}">
<a href="/admin/customization">Customization</a>
</li>
<li class="navigation__item{{#if current}} active{{/if}}">
<a href="/admin/employees">Employee</a>
</li>
</ul>
</aside>
And here is a snippet of my routes file:
app.get("/admin/:directory/:page", require("connect-ensure-login").ensureLoggedIn("/admin"), (req, res) => {
if (req.params.page === "new") {
res.render("admin/" + req.params.directory + "/new", Object.assign({ layout: "layouts/admin", navHighlight: "active" }, app.get("result")[0]));
} else {
employeeService.find({ query: { Slug: req.params.page }}, (error, employee) => {
employee = employee[0];
res.render("admin/employees/employee", Object.assign({ employeeRequest: req.params.page, Title: "Admin | " + employee.Name, layout: "layouts/admin" }, app.get("result")[0]));
});
}
});
Has someone accomplished something like this yet? I've searched SO and elsewhere and haven't found anything.