C
C#•4w ago
Casper

How to add razor pages to razor class library and reference from Blazor server project?

I am trying to place all my razor pages and components inside a razor class library to modularize the code to pack as a nuget package. I can get the components rendered but routing to pages just wont work. I have added the assembly to be scanned in the blazor web project as such and referenced the project in the csproj file:
@using System.Reflection
@using AppBlueprint.UiKit.Components.Pages

<Router AppAssembly="@typeof(Program).Assembly"
AdditionalAssemblies="@AdditionalAssemblies">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<MudText Typo="Typo.h6">Sorry, there's nothing here!</MudText>
</NotFound>
</Router>

@code {
private Assembly[] AdditionalAssemblies { get; } = new[] { typeof(AppBlueprint.UiKit.Components.Pages.Dashboard).Assembly };

protected override void OnInitialized()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine($"Loaded Assembly: {assembly.FullName}");
}
}
}
@using System.Reflection
@using AppBlueprint.UiKit.Components.Pages

<Router AppAssembly="@typeof(Program).Assembly"
AdditionalAssemblies="@AdditionalAssemblies">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<MudText Typo="Typo.h6">Sorry, there's nothing here!</MudText>
</NotFound>
</Router>

@code {
private Assembly[] AdditionalAssemblies { get; } = new[] { typeof(AppBlueprint.UiKit.Components.Pages.Dashboard).Assembly };

protected override void OnInitialized()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine($"Loaded Assembly: {assembly.FullName}");
}
}
}
`
3 Replies
Casper
CasperOP•4w ago
Do you have any suggestions what else to try out?
Sehra
Sehra•4w ago
ASP.NET Core Blazor routing and navigation
Learn how to manage Blazor app request routing and how to use the Navigation Manager and NavLink component for navigation.
Casper
CasperOP•4w ago
i read that and did the requirements but it wont work still 😦 finally it wortks !

Did you find this page helpful?