我为管理面板划分了页眉,页脚和侧边栏。我已根据需要在边栏中应用了链接。问题是我的管理员URL是example.com/admin(侧边栏仪表板菜单链接),而设置URL是example.com/admin/settings。现在,当我从侧边栏上单击仪表板时,“活动”类添加到所有具有example.com/admin/{next_url_path}的侧边栏菜单链接中。我正在Codeigniter中开发管理面板,如何解决此错误?
sidebar.php
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<li class="nav-item">
<?php echo anchor('admin', '<span class="menu-title"><i class="mdi mdi-home menu-icon"></i> Dashboard</span>', 'class="nav-link"'); ?>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#settings" aria-expanded="false" aria-controls="settings">
<span class="menu-title">
<i class="mdi mdi-settings menu-icon"></i> Settings
</span>
<i class="menu-arrow"></i>
</a>
<div class="collapse" id="settings">
<ul class="nav flex-column sub-menu">
<li class="nav-item">
<?php echo anchor('admin/settings', 'Settings', 'class="nav-link"'); ?>
</li>
<li class="nav-item">
<?php echo anchor('admin/activityLog', 'Activity Log', 'class="nav-link"'); ?>
</li>
</ul>
</div>
</li>
</ul>
</nav>
用于添加活动类的js
var current = location.pathname.split("/").slice(-1)[0].replace(/^\/|\/$/g, '');
$('.nav li a', sidebar).each(function() {
var $this = $(this);
if (current === "") {
//for root url
if ($this.attr('href').indexOf(current) !== -1) {
$(this).parents('.nav-item').last().addClass('active');
if ($(this).parents('.sub-menu').length) {
$(this).closest('.collapse').addClass('show');
$(this).addClass('active');
}
}
} else {
//for other url
if ($this.attr('href').indexOf(current) !== -1) {
$(this).parents('.nav-item').last().addClass('active');
if ($(this).parents('.sub-menu').length) {
$(this).closest('.collapse').addClass('show');
$(this).addClass('active');
}
}
}
})