Blazor服务器端应用程序上的Child Blazor应用程序 [英] Child Blazor app on Blazor Server side app
问题描述
将Client Blazor应用添加到Server Blazor应用
Adding a Client side Blazor app to a Server Side Blazor app
嗨
在此关注有用的答案
我遇到了这样一种情况,能够将客户端Blazor应用程序添加到Blazor服务器端应用程序会很有帮助
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
我创建了Blazor服务器应用程序,将客户端应用程序附加到服务器应用程序,并调整了服务器startup.cs以映射子应用程序.我还确认了客户端应用的index.html基值正确
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>();
});
当我转到localhost/subapp页面时,父应用程序显示对不起,此地址没有任何内容.",我可以看到父应用程序正在拦截路由
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?
谢谢
标记
推荐答案
感谢来自火星的agua"的建议,并阅读了下面的链接,我尝试更改app.map的使用顺序
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
将app.map移至app.UseRouting()之前;创建预期的结果
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
这篇关于Blazor服务器端应用程序上的Child Blazor应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!