Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Web App NavigationManager in Client -> Exception_WasThrown

$
0
0

I was creating a Blazor Web App using VS2022. Here is the project overview:Blazor Web App project overview

When using the NavigationManager in the code section of the Client project I get an Exception_WasThrown error:Exception

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


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>