简体   繁体   中英

Child Blazor app on Blazor Server side app

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM