using Blazorcrud.Client.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Rendering; using System.Net; namespace Blazorcrud.Client.Shared { public class AppRouteView : RouteView { [Inject] public NavigationManager NavigationManager { get; set; } [Inject] public IUserService UserService { get; set; } protected override void Render(RenderTreeBuilder builder) { var authorize = Attribute.GetCustomAttribute(RouteData.PageType, typeof(AuthorizeAttribute)) != null; if (authorize && UserService.User == null) { var returnUrl = WebUtility.UrlEncode(new Uri(NavigationManager.Uri).PathAndQuery); NavigationManager.NavigateTo($"user/login?returnUrl={returnUrl}"); } else { base.Render(builder); } } } }