1
votes

Adding a Client side Blazor app to a Server Side Blazor app

Hi

Following on to the helpful answer here

Blazor sub app 404 error after upgrade to Preview 6

I have run into a situation where it would be helpful to be able to add a Client side Blazor app to a Blazor server side app

I have created the Blazor Server app, attached a client app the the server app, and adjusted the server startup.cs to map the child app. I have also confirmed the client apps index.html base value is correct

 app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
        });

 app.Map("/subapp", child =>
        {
            child.UseRouting();
            child.UseEndpoints(endpoints =>
            {

endpoints.MapFallbackToClientSideBlazor<BlazorCoreHosted.Subapp.Startup>("index.html");
            });
            child.UseClientSideBlazorFiles<BlazorCoreHosted.Subapp.Startup>();
        });

When I go to the localhost/subapp page the parent app shows "Sorry, there's nothing at this address.", and I can see the parent app is intercepting the routing

Is there a way to get around this, or is this not a valid scenario?

Thanks

Mark

1
Did you try to invert the order ? Call 1st app.Map then app.UseEndpoints, the order matter - agua from mars
Revering the order, calling app.map ahead of UseEnpoints, goes straight to the main app when I go to the ./subapp url - no "Sorry, there's nothing at this address." - Mark Shortt
Did you try without the leading / in your Map ? app.Map("subapp") - agua from mars
Removing the / in the map gives the error : 'The path in 'value' must start with '/'. ' - Mark Shortt
Did you try to delete obj and bin folders and rebuild ? - agua from mars

1 Answers

1
votes

Thanks to the suggestion from 'agua from mars', and reading the link below I experimented with changing the order of where I use app.map

Moving app.map to before app.UseRouting(); creates the expected result

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.0