| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- @model SharedKernel.Constants.Menu
- @inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
- @{
- // 현재 요청 경로 가져오기
- var currentPath = HttpContextAccessor.HttpContext?.Request?.Path.ToString()?.TrimEnd('/');
- // 고정된 메뉴 경로
- var menuPath = (Model.Path?.TrimEnd('/') ?? string.Empty).ToLower();
- bool isActive = false;
- bool isParentActive = false;
- // "게시판 관리" 특별 처리
- if (Model.Name.Equals("게시판 관리", StringComparison.OrdinalIgnoreCase))
- {
- string[] activePrefixes = { "/forum/board/meta", "/forum/board/prefix", "/forum/board/manager", "/forum/board/list" };
- isActive = currentPath != null && activePrefixes.Any(prefix =>
- currentPath.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)
- );
- }
- else if (Model.Children != null && Model.Children.Any())
- {
- // 자식 메뉴 중 하나가 활성화되었는지 확인
- isParentActive = Model.Children.Any(child =>
- !string.IsNullOrEmpty(currentPath) &&
- !string.IsNullOrEmpty(child.Path) &&
- (currentPath.Equals(child.Path, StringComparison.OrdinalIgnoreCase) || currentPath.StartsWith(child.Path + "/", StringComparison.OrdinalIgnoreCase))
- );
- // 부모 메뉴 자체는 active 주지 않음
- isActive = false;
- }
- else
- {
- // 일반 메뉴 active 여부 판단
- isActive = !string.IsNullOrEmpty(currentPath) && !string.IsNullOrEmpty(menuPath) && (currentPath.Equals(menuPath, StringComparison.OrdinalIgnoreCase) || currentPath.StartsWith(menuPath + "/", StringComparison.OrdinalIgnoreCase));
- }
- }
- <li class="nav-item">
- <a href="@Model.Path" class="nav-link @(isActive ? "active" : "") @Html.Raw(Model.Children == null || !Model.Children.Any() ? "collapsed" : "")"
- @Html.Raw(Model.Children != null && Model.Children.Any() ? "data-bs-toggle=\"collapse\"" : "")
- @Html.Raw(Model.Children != null && Model.Children.Any() ? $"data-bs-target=\"#menu-{Model.Id}\"" : "")
- >
- @if (!string.IsNullOrEmpty(Model.Icon))
- {
- @Html.Raw(Model.Icon);
- }
- @Model.Name
- </a>
- @if (Model.Children != null && Model.Children.Any())
- {
- <ul id="menu-@Model.Id" class="nav flex-column flex-nowrap ps-3 collapse">
- @foreach (var child in Model.Children)
- {
- @* @Html.Partial("_MenuItem", child); *@
- <partial name="_MenuItem" model="child" />
- }
- </ul>
- }
- </li>
|