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

Referencing a razor page from a Razor Class Library is giving a 404 error

$
0
0

I am trying to reference a razor page contained in a Razor Class Library in a Blazor project. When I go to the route of my page I am getting a 404 error.

Steps to recreate

Create a new solution as a Blazor Web App (.NET 8.0) template.Add a new Razor Class Library project (Support pages and views checked)Edit the Page1.cshtml and have the following at the top:

@page "/test"

Add a reference to the Razor Class Library(RazorClassLibrary1) from the Blazor App (BlazorApp1).

In BlazorApp1 edit Routes.razor to be:

<Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="new[]{typeof(RazorClassLibrary1.MyFeature.Pages.Page1Model).Assembly}"><Found Context="routeData"><RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" /><FocusOnNavigate RouteData="routeData" Selector="h1" /></Found></Router>

Edit Program.cs of BlazorApp1 to include:

  app.MapRazorComponents<App>()      .AddInteractiveServerRenderMode()      .AddAdditionalAssemblies([typeof(RazorClassLibrary1.MyFeature.Pages.Page1Model).Assembly] );

Start the application and browse to /test and you get a 404. What am I doing wrong?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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