danroth27 / Net8BlazorWebAssembly

ASP.NET Core hosted Blazor WebAssembly app with .NET 8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blazor WebAssembly in .NET 8

This project demonstrates how to build an ASP.NET Core hosted Blazor WebAssembly app with .NET 8 and how to upgrade existing apps to take advantage of the latest features.

To upgrade an existing ASP.NET Core hosted Blazor WebAssembly app to .NET 8:

  1. Update the project file to target net8.0 and package references to the latest .NET 8 versions (commit).
  2. Move content from Client/wwwroot/index.html to Host.razor (commit):
    1. Update script to blazor.web.js.
    2. Replace title tag with HeadOutlet component.
  3. Update Client/Program.cs (commit):
    1. Remove builder.RootComponents.Add<HeadOutlet>("head::after").
  4. Update Server/Program.cs (commit):
    1. Add builder.Services.AddRazorComponents().AddWebAssemblyComponents().
    2. Remove app.UseBlazorFrameworkFiles().
    3. Replace MapFallbackToFile("index.html") with app.MapRazorComponents<Host>().AddWebAssemblyRenderMode().

To enable prerendering:

  1. Update all components to support prerendering from the server (commit).
  2. In Host.razor replace the id=app tag with <App @rendermode="@RenderMode.WebAssembly" /> (commit).

Open issues:

About

ASP.NET Core hosted Blazor WebAssembly app with .NET 8

License:MIT License


Languages

Language:HTML 39.1%Language:CSS 35.7%Language:C# 25.2%