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

Why is routing from one Razor component to another, both defined in the same RCL, does not work?

$
0
0

I have two minimal projects in my .NET 8 solution: a Blazor web server app, interactive server rendering, with Home.razor page, and aRazor class library with two components defined, Schedule and CodeView.

My Home.razor is:

@page "/"@inject IServiceProvider ServiceProvider<h3>Registered Routes</h3><ul>    @foreach (var route in Routes)    {<li>Route: @route End Route</li>    }</ul><PageTitle>Home</PageTitle><ScheduleView />@code {    private List<string> Routes { get; set; } = new();    protected override void OnInitialized()    {        var routeDataSource = ServiceProvider.GetRequiredService<IEnumerable<EndpointDataSource>>();        foreach (var r in routeDataSource)        {            foreach (var ep in r.Endpoints)                Routes.Add(ep.ToString());        }    }}

My ScheduleView.razor is:

@page "/scheduleview"<ul class="nav nav-tabs"><li class="nav-item"><NavLink class="nav-link" activeClass="active" href="/codeview">PageWithForwardSlash</NavLink></li><li class="nav-item"><NavLink class="nav-link" activeClass="active" href="codeview">Logic</NavLink></li></ul>

My CodeView.razor is:

@page "/codeview"<h3>CodeView</h3>@code {}

My inclusion of the assembly for the routes is:

app.MapRazorComponents<App>()    .AddInteractiveServerRenderMode()    .AddAdditionalAssemblies(new[] { typeof(LuahSV.ScheduleView).Assembly }) ;

Results

  • ScheduleView is shown correctly in Home

Routes are outputing as:

Route: Blazor web static files End RouteRoute: Blazor Opaque Redirection End RouteRoute: /Error (/Error) End RouteRoute: / (/) End RouteRoute: /weather (/weather) End RouteRoute: /codeview (/codeview) End RouteRoute: /scheduleview (/scheduleview) End RouteRoute: Microsoft.AspNetCore.Routing.RouteEndpoint End RouteRoute: Microsoft.AspNetCore.Routing.RouteEndpoint End RouteRoute: Microsoft.AspNetCore.Routing.RouteEndpoint End RouteRoute: Microsoft.AspNetCore.Routing.RouteEndpoint End RouteRoute: Microsoft.AspNetCore.Routing.RouteEndpoint End Route

Problem: when I click on the links in ScheduleView, I am getting an error "not found". Why?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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