I’m building a .NET 8 Blazor WebAssembly app with prerendering (InteractiveWebAssembly). When navigating via links, everything works fine. But if I manually enter a URL (e.g., /login), the server prerenders before WASM loads, causing crashes due to missing client-only services (e.g., ILocalStorageService).
MY SOLUTION=>Delay Rendering Until WASM LoadsInstead of letting the server render pages that need client-only services, I show a loading screen until WASM takes over.
@if (!_isLoaded){<div id="app-loading">Loading...</div>}else{<div class="page"><NavMenu /><main>@Body</main></div>}@code { private bool _isLoaded = false; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JSRuntime.InvokeVoidAsync("console.log", "Client ready"); _isLoaded = true; StateHasChanged(); } }}Is there a better way to prevent crashes while keeping it simple and scalable?