@inject AppState AppState; @inject NavigationManager NavigationManager; @inject IStringLocalizer i18n @implements IDisposable; @if (handleAppBarContainer()) { } @code { bool Opened = false; static int Index = 1; void ButtonClicked() { Opened = !Opened; } void ButtonClicked(int _Index) { Index = _Index; ButtonClicked(); if (_Index == 4) { AppState.LoggedIn = false; } } protected override void OnInitialized() { AppState.OnChange += StateHasChanged; NavigationManager.LocationChanged += LocationChanged; base.OnInitialized(); } public void Dispose() { AppState.OnChange -= StateHasChanged; NavigationManager.LocationChanged -= LocationChanged; } void LocationChanged(object sender, LocationChangedEventArgs e) { if (isInServicesUrl(e)) { Index = 1; } else if (e.Location.Contains("account")) { Index = 2; } else if (e.Location.Contains("info")) { Index = 3; } else { Index = 4; } } bool isInServicesUrl(LocationChangedEventArgs e) { return (e.Location.Contains("caritas_services") || e.Location.Contains("lost_found") || e.Location.Contains("keydata") || e.Location.Contains("account/") || e.Location.Contains("conclusion_")); } bool handleAppBarContainer() { string uri = NavigationManager.Uri; string baseUri = NavigationManager.BaseUri; string delta = uri.Replace(baseUri, ""); if (delta == null || delta.Equals("")) { Index = 4; return false; } else { if (delta.Equals("caritas_services")) { Index = 1; } else if (delta.Equals("account")) { Index = 2; } else if (delta.Equals("info")) { Index = 3; } return true; } } }