I have Blazor Web App, interactive mode is Auto and location per page/component.Since App, Routes and Layouts are rendered statically on the server, every navigation causes BrowserInfo(registred as Scoped) is injected new. So how to achieve persisting state with Auto render mode without Singleton service to have this state only for one user?The thing is, i want to set set layout in Routes.razor based on detectiong iframeThe project cannot have globally available interactivity (such as Blazor Server).
I have it like this right know:
App.razor:
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><base href="/" /><link rel="stylesheet" href="bootstrap/bootstrap.min.css" /><link rel="stylesheet" href="app.css" /><link rel="stylesheet" href="BlazorAppAuto.styles.css" /><link rel="icon" type="image/png" href="favicon.png" /><script> if (window.self !== window.top) { sessionStorage.setItem('iframe', 'true'); } else { sessionStorage.setItem('iframe', 'true'); } const iframeValue = sessionStorage.getItem('iframe'); const url = new URL(window.location); if (url.searchParams.get('iframe') !== iframeValue) { url.searchParams.set('iframe', iframeValue); window.location.href = url.toString(); }</script><HeadOutlet /></head><body><Routes /></body></html>Routes.razor
<Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly, typeof(BasketApp.UI.DependencyInjection).Assembly }"><Found Context="routeData"><CascadingValue Value="routeData" ><AuthorizeRouteView RouteData="routeData" DefaultLayout="BrowserInfo.IsIframe ? typeof(FrameLayout) : typeof(MainLayout)"><NotAuthorized> @if (context.User.Identity?.IsAuthenticated is not true) { // <RedirectToLogin /> } else {<BasketApp.UI.Components.Common.ErrorsAlert Errors="@([ErrorOr.Error.Forbidden(description: "You are not authorized to access this resource.")])" /> }</NotAuthorized><Authorizing> Authorizing...</Authorizing></AuthorizeRouteView><FocusOnNavigate RouteData="routeData" Selector="h1" /></CascadingValue></Found></Router>@code { [SupplyParameterFromQuery(Name = "iframe")] public bool IFrame { get; set; } @inject BrowserInfo BrowserInfo; protected override void OnInitialized() { if (BrowserInfo.IsIframe) return; BrowserInfo.IsIframe = IFrame; base.OnInitialized(); }}or second choice is not setting layouts in Routes but in MainLayout
@inject BrowserInfo BrowserInfo @if (!BrowserInfo.IsIframe) {<NavMenu @rendermode=PreferredRenderMode /> }[SupplyParameterFromQuery(Name = "iframe")] public bool IFrame { get; set; } @inject BrowserInfo BrowserInfo; protected override void OnInitialized() { if (BrowserInfo.IsIframe) return; BrowserInfo.IsIframe = IFrame; base.OnInitialized(); }