Pablo Arthur
Pablo Arthur

Reputation: 11

Blazor router, How to have multiple Client Side Blazor projects in a Net Core app?

I have a Web solution with a WebCore 3.0 razor pages that its huge!. Lets call this the WebCoreAppDefault. I want to implement 3 Blazor projects with different pages. In my Start up files I have configure as this:

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseClientSideBlazorFiles<BlazorApp1.Startup>();
app.UseClientSideBlazorFiles<BlazorApp2.Startup>();
app.UseClientSideBlazorFiles<BlazorApp3.Startup>();
app.UseRouting();

app.UseAuthorization();`enter code here`

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
    endpoints.MapFallbackToClientSideBlazor<BlazorApp1.Startup>("ReportGenerator.html");
     endpoints.MapFallbackToClientSideBlazor<BlazorApp2.Startup>("DashboardConfiguration.html");
     endpoints.MapFallbackToClientSideBlazor<BlazorApp3.Startup>("ClaimsManipulation.html");

I do have the startup html file in each project as this: 1.- in the BlazorApp1 I have the ReportGenerator.html file under the wwwroot 1.- in the BlazorApp2 I have the DashboardConfiguration.html file under the wwwroot 1.- in the BlazorApp3 I have the ClaimsManipulation.html file under the wwwroot

When I run my WebCoreAppDefault, I can get to each Blazor file by adding a /ReportGenerator.html, or DashboardConfiguration.html, or ClaimsManipulation.html, and Blazor will load the project, but that's it.

The router of the blazor will not load any page, It will said "Sorry there is nothing at this address" on the not found. If I can put a link tag to the /Counter page, I can run the counter page without any layouts.

I believe I have problems after the blazor loads the mono and the dll, to redirect to another page that is not the root or "/" page?

I am trying to redirect in each project to a page that is not page "/", How Can I do that?

I want to understand how I can redirect to a page that is not root? or how to configure the App.razor page to redirect to a ReportGenerator.razor page or DashboardConfiguration.razor page or ClaimsManipulation.razor page as a landing page instead of being force to /

Upvotes: 1

Views: 1441

Answers (1)

Eric Holland
Eric Holland

Reputation: 401

This is now possible. Searched all over, the thread below has a snippet which I was able to use.

https://github.com/dotnet/aspnetcore/issues/17997

2 changes you need to make for each Blazor clientside project you want to host.

Change 1 Open index.html of Blazor clientside project and change base to the url path you want enter image description here

Change 2 Open Startup.cs in Blazor Serverside project and map your clientside project to a particular URL pattern. enter image description here

Upvotes: 2

Related Questions