I was creating a Blazor Web App using VS2022. Here is the project overview:
When using the NavigationManager in the code section of the Client project I get an Exception_WasThrown error:
Here is the Home.razor content in BlazorApp.Client:
@page "/"@inject NavigationManager NavigationManager<PageTitle>Home</PageTitle><h1>Hello, world!</h1>Welcome to your new app.@code { protected override void OnInitialized() { NavigationManager.NavigateTo("/weather"); }}I already added this:
app.MapRazorComponents<App>() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(BlazorApp1.Client._Imports).Assembly);to Program.cs in the BlazorApp project and I have updated my Routes.razor in the Client project as follows:
<Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }"><Found Context="routeData"><RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" /><FocusOnNavigate RouteData="routeData" Selector="h1" /></Found></Router>Anything I am missing here?
Thanks!
I was trying adding the assembly to the Project.cs as well as the Route.razor according to https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-8.0